当前位置:网站首页>AcWing 1126. 最小花费 题解(最短路—dijkstra)
AcWing 1126. 最小花费 题解(最短路—dijkstra)
2022-07-02 18:27:00 【乔大先生】
AcWing 1126. 最小花费
朴素版dijkstra算法求最短路,又熟悉了一遍模板,注意题意,需要将给出的值转化成折损率,之后套用最短路模型求出折损率之积最大的一条路的折损率之积(为什么要折损率之积最大见如下公式:)
#include<bits/stdc++.h>
using namespace std;
#define db double
const int N = 2100, M = 2e5 + 10;
db g[N][N];
db d[N];
int n, m;
int S, T;
bool st[N];
void dijkstra(){
d[S] = 1;
for(int i = 1; i <= n; i ++ ){
int t = -1;
for(int j = 1; j <= n; j ++ ){
if(!st[j] && (t == -1 || d[t] < d[j])) t = j;
}
st[t] = true;
for(int j = 1; j <= n; j ++ ){
d[j] = max(d[j], d[t] * g[t][j]);
}
}
}
int main()
{
cin>>n>>m;
while(m -- ){
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
db z = (100.0 - c) / 100; //特殊处理,将扣的钱直接转化为折损率,题意即转化成折损率成绩最大的一条路,还是最短路模型
g[a][b] = g[b][a] = max(g[a][b], z);
}
cin>>S>>T;
dijkstra();
printf("%.8lf\n", 100 / d[T]);
return 0;
}
边栏推荐
- juypter notebook 修改默认打开文件夹以及默认浏览器
- Which video recording software is better for the computer
- 移动机器人路径规划:人工势场法[通俗易懂]
- 教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5
- 函数高阶-柯里化实现
- 电脑使用哪个录制视频软件比较好
- Refactoring: improving the design of existing code (Part 1)
- AcWing 1129. 热浪 题解(最短路—spfa)
- C file input operation
- Emmet基础语法
猜你喜欢

What is 9D movie like? (+ common sense of dimension space)

搭建哨兵模式reids、redis从节点脱离哨兵集群

Introduction to the paper | analysis and criticism of using the pre training language model as a knowledge base

Tutorial (5.0) 10 Troubleshooting * fortiedr * Fortinet network security expert NSE 5

注解开发方式下AutowiredAnnotationBeanPostProcessor的注册时机

Chic Lang: completely solve the problem of markdown pictures - no need to upload pictures - no need to network - there is no lack of pictures forwarded to others

Watchful pioneer world outlook Architecture - (how does a good game come from)

Excel finds the same value in a column, deletes the row or replaces it with a blank value

《重构:改善既有代码的设计》读书笔记(下)

高级性能测试系列《24. 通过jdbc执行sql脚本》
随机推荐
mybatiesHelperPro工具必须的可以生成到对应项目文件夹下
Imitation Jingdong magnifying glass effect (pink teacher version)
450-深信服面经1
Binary operation
NPOI导出Excel2007
When converting from list to map, if a certain attribute may cause key duplication and exceptions, you can set the way to deal with this duplication
Watchful pioneer world outlook Architecture - (how does a good game come from)
程序猿入门攻略(十二)——数据的存储
多态的理解以及作用
Talk about the design of red envelope activities in e-commerce system
juypter notebook 修改默认打开文件夹以及默认浏览器
Introduction to the paper | analysis and criticism of using the pre training language model as a knowledge base
In pytorch function__ call__ And forward functions
注解开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
【ERP软件】ERP体系二次开发有哪些危险?
AcWing 1134. 最短路计数 题解(最短路)
IDEA编辑器去掉sql语句背景颜色SQL语句警告No data sources are configured to run this SQL...和SQL Dialect is Not Config
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
metric_ Logger urination
Preprocessing and preprocessing macros