当前位置:网站首页>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;
}
边栏推荐
- Codeworks 5 questions per day (1700 average) - day 4
- 预处理和预处理宏
- Introduction to the paper | application of machine learning in database cardinality estimation
- AcWing 1127. 香甜的黄油 题解(最短路—spfa)
- C文件输入操作
- golang:[]byte转string
- How to print mybats log plug-in using XML file
- Reading notes of code neatness
- 云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统
- 安装单机redis详细教程
猜你喜欢
Bubble sort array

《架构整洁之道》读书笔记(下)

How performance testing creates business value

Transformation of thinking consciousness is the key to the success or failure of digital transformation of construction enterprises

Yolov3 trains its own data set to generate train txt

High frequency interview questions

教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 網絡安全專家 NSE 5

教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5

全志A33使用主线U-Boot

教程篇(5.0) 09. RESTful API * FortiEDR * Fortinet 网络安全专家 NSE 5
随机推荐
【pytorch学习笔记】Tensor
Npoi export Excel2007
Compile oglpg-9th-edition source code with clion
注解开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
NPOI导出Excel2007
Talk about the design of red envelope activities in e-commerce system
Binary operation
Reading notes of code neatness
MySQL advanced (Advanced) SQL statement
IDEA编辑器去掉sql语句背景颜色SQL语句警告No data sources are configured to run this SQL...和SQL Dialect is Not Config
MySQL
End to end object detection with transformers (Detr) paper reading and understanding
codeforces每日5题(均1700)-第四天
为什么要做企业固定资产管理系统,企业如何加强固定资产管理
Digital scroll strip animation
PyTorch函数中的__call__和forward函数
Typescript 之 快速入门
Golang并发编程——goroutine、channel、sync
Fastdfs installation
Tutoriel (5.0) 10. Dépannage * fortiedr * fortinet Network Security expert NSE 5