当前位置:网站首页>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 修改默认打开文件夹以及默认浏览器
- What is 9D movie like? (+ common sense of dimension space)
- 《代碼整潔之道》讀書筆記
- Codeworks 5 questions per day (1700 average) - day 4
- 为什么要做企业固定资产管理系统,企业如何加强固定资产管理
- Juypter notebook modify the default open folder and default browser
- Typescript 之 快速入门
- mysql备份后缀是什么_mysql备份还原
- Binary operation
- 云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统
猜你喜欢

Thread application instance

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

AcWing 903. 昂贵的聘礼 题解(最短路—建图、dijkstra)

Quanzhi A33 uses mainline u-boot

IEDA refactor的用法

In pytorch function__ call__ And forward functions

PHP parser badminton reservation applet development requires online system

搭建主从模式集群redis

Compile oglpg-9th-edition source code with clion

Markdown basic grammar
随机推荐
Use cheat engine to modify money, life and stars in Kingdom rush
PHP非对称加密方法私钥及公钥加密解密的方法
预处理和预处理宏
中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
Windows2008R2 安装 PHP7.4.30 必须 LocalSystem 启动应用程序池 不然500错误 FastCGI 进程意外退出
MySQL advanced (Advanced) SQL statement
Date tool class (updated from time to time)
Gmapping code analysis [easy to understand]
The mybatieshelperpro tool can be generated to the corresponding project folder if necessary
Usage of ieda refactor
Quanzhi A33 uses mainline u-boot
Data dimensionality reduction factor analysis
End-to-End Object Detection with Transformers(DETR)论文阅读与理解
Mobile robot path planning: artificial potential field method [easy to understand]
Digital scroll strip animation
Introduction of Ethernet PHY layer chip lan8720a
2022 software engineering final exam recall Edition
AcWing 1137. 选择最佳线路 题解(最短路)
QT中的QPropertyAnimation使用和toast案列
4274. 后缀表达式-二叉表达式树