当前位置:网站首页>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;
}
边栏推荐
- Tutorial (5.0) 10 Troubleshooting * fortiedr * Fortinet network security expert NSE 5
- AcWing 1127. 香甜的黄油 题解(最短路—spfa)
- 注解开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
- QT中的QPropertyAnimation使用和toast案列
- High frequency interview questions
- Introduction to the paper | application of machine learning in database cardinality estimation
- End to end object detection with transformers (Detr) paper reading and understanding
- 电脑使用哪个录制视频软件比较好
- 以太网PHY层芯片LAN8720A简介
- SIFT feature point extraction "suggestions collection"
猜你喜欢

Refactoring: improving the design of existing code (Part 1)

Windows2008R2 安装 PHP7.4.30 必须 LocalSystem 启动应用程序池 不然500错误 FastCGI 进程意外退出

Imitation Jingdong magnifying glass effect (pink teacher version)
![[paper reading] Ca net: leveraging contextual features for lung cancer prediction](/img/ef/bb48ee88d5dc6fe876a498ab53106e.png)
[paper reading] Ca net: leveraging contextual features for lung cancer prediction

Introduction to the paper | application of machine learning in database cardinality estimation

Use cheat engine to modify money, life and stars in Kingdom rush

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

End-to-End Object Detection with Transformers(DETR)论文阅读与理解

Educational Codeforces Round 129 (Rated for Div. 2) 补题题解

How performance testing creates business value
随机推荐
2022 compilation principle final examination recall Edition
Which video recording software is better for the computer
IEDA refactor的用法
AcWing 1137. 选择最佳线路 题解(最短路)
C的内存管理
机器学习笔记 - 时间序列预测研究:法国香槟的月销量
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5
Tutoriel (5.0) 10. Dépannage * fortiedr * fortinet Network Security expert NSE 5
Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
SIFT feature point extraction "suggestions collection"
ICDE 2023|TKDE Poster Session(CFP)
High frequency interview questions
Reading notes of code neatness
[test development] takes you to know what software testing is
中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
Usage of ieda refactor
2022.7.1-----leetcode. two hundred and forty-one
第七章-类基础
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
mybatiesHelperPro工具必须的可以生成到对应项目文件夹下