当前位置:网站首页>AcWing 1126. Minimum cost solution (shortest path Dijkstra)
AcWing 1126. Minimum cost solution (shortest path Dijkstra)
2022-07-02 19:40:00 【Mr. Qiao Da】
AcWing 1126. Minimum cost
Plain version dijkstra Algorithm for the shortest path , Familiar with the template again , Pay attention to the meaning of the question , You need to convert the given value into a loss rate , Then apply the shortest path model to calculate the product of the loss rate of the path with the largest product of the loss rate ( Why should we maximize the product of the loss rate? See the following formula :)
#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; // Special treatment , Convert the deducted money directly into the discount rate , The meaning of the question is to transform it into the road with the greatest loss rate , Or the shortest path model
g[a][b] = g[b][a] = max(g[a][b], z);
}
cin>>S>>T;
dijkstra();
printf("%.8lf\n", 100 / d[T]);
return 0;
}
边栏推荐
- Npoi export Excel2007
- Notes de lecture sur le code propre
- Codeworks round 802 (Div. 2) pure supplementary questions
- What is the MySQL backup suffix_ MySQL backup restore
- AcWing 1134. Shortest circuit counting problem solution (shortest circuit)
- Correspondence between pytoch version, CUDA version and graphics card driver version
- 高并发下如何避免产生重复数据?
- KT148A语音芯片ic的用户端自己更换语音的方法,上位机
- KT148A语音芯片ic的开发常见问题以及描述
- Gamefi chain game system development (NFT chain game development function) NFT chain game system development (gamefi chain game development source code)
猜你喜欢
Bubble sort array

KT148A语音芯片ic的硬件设计注意事项

Py之interpret:interpret的简介、安装、案例应用之详细攻略

Introduction to mongodb chapter 03 basic concepts of mongodb

AcWing 340. 通信线路 题解(二分+双端队列BFS求最短路)

Set up sentinel mode. Reids and redis leave the sentinel cluster from the node

Machine learning notes - time series prediction research: monthly sales of French champagne

Data dimensionality reduction factor analysis

SQLite 3.39.0 release supports right external connection and all external connection

良心总结!Jupyter Notebook 从小白到高手,保姆教程来了!
随机推荐
定了,就是它!
Machine learning notes - time series prediction research: monthly sales of French champagne
AcWing 903. 昂贵的聘礼 题解(最短路—建图、dijkstra)
AcWing 1135. 新年好 题解(最短路+搜索)
AcWing 1134. Shortest circuit counting problem solution (shortest circuit)
[pytorch learning notes] tensor
Windows2008r2 installing php7.4.30 requires localsystem to start the application pool, otherwise 500 error fastcgi process exits unexpectedly
Introduction to mongodb chapter 03 basic concepts of mongodb
Chapter 7 - class foundation
AcWing 1134. 最短路计数 题解(最短路)
Gamefi链游系统开发(NFT链游开发功能)丨NFT链游系统开发(Gamefi链游开发源码)
AcWing 181. 回转游戏 题解(搜索—IDA*搜索)
AcWing 1137. 选择最佳线路 题解(最短路)
职场四象限法则:时间管理四象限与职场沟通四象限「建议收藏」
Think about the huge changes caused by variables
嵌入式(PLD) 系列,EPF10K50RC240-3N 可编程逻辑器件
checklistbox控件用法总结
Istio1.12:安装和快速入门
Use cheat engine to modify money, life and stars in Kingdom rush
Function high order curry realization