当前位置:网站首页>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;
}
边栏推荐
- 机器学习笔记 - 时间序列预测研究:法国香槟的月销量
- golang:[]byte转string
- 安装单机redis详细教程
- Data dimensionality reduction factor analysis
- AcWing 1137. 选择最佳线路 题解(最短路)
- Imitation Jingdong magnifying glass effect (pink teacher version)
- MySQL advanced (Advanced) SQL statement
- 《架构整洁之道》读书笔记(下)
- 二进制操作
- Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
猜你喜欢

Use cheat engine to modify money, life and stars in Kingdom rush
![[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

Imitation Jingdong magnifying glass effect (pink teacher version)

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

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

Codeworks 5 questions per day (1700 average) - day 4

Thread application instance

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

安装单机redis详细教程

Machine learning notes - time series prediction research: monthly sales of French champagne
随机推荐
How to print mybats log plug-in using XML file
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5
2022 compilation principle final examination recall Edition
Use cheat engine to modify money, life and stars in Kingdom rush
Codeworks 5 questions per day (1700 average) - day 4
[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
Codeforces Round #802 (Div. 2) 纯补题
Reading notes of code neatness
SIFT feature point extraction "suggestions collection"
函数高阶-柯里化实现
Compile oglpg-9th-edition source code with clion
Virtual machine initialization script, virtual machine mutual secret key free
《架构整洁之道》读书笔记(下)
Qpropertyanimation use and toast case list in QT
Preprocessing and preprocessing macros
Watchful pioneer world outlook Architecture - (how does a good game come from)
2022.7.1-----leetcode.241
MySQL
程序猿入门攻略(十二)——数据的存储
为什么要做企业固定资产管理系统,企业如何加强固定资产管理