当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode
嵌入式(PLD) 系列,EPF10K50RC240-3N 可编程逻辑器件
Refactoring: improving the design of existing code (Part 1)
AcWing 903. 昂贵的聘礼 题解(最短路—建图、dijkstra)
Dictionaries
程序猿入门攻略(十二)——数据的存储
良心总结!Jupyter Notebook 从小白到高手,保姆教程来了!
SQLite 3.39.0 release supports right external connection and all external connection
Thread application instance
ShardingSphere-JDBC5.1.2版本关于SELECT LAST_INSERT_ID()本人发现还是存在路由问题
随机推荐
Refactoring: improving the design of existing code (Part 2)
Getting started with typescript
《重构:改善既有代码的设计》读书笔记(上)
Golang并发编程——goroutine、channel、sync
[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
Windows2008r2 installing php7.4.30 requires localsystem to start the application pool, otherwise 500 error fastcgi process exits unexpectedly
《重构:改善既有代码的设计》读书笔记(下)
Function high order curry realization
高并发下如何避免产生重复数据?
What is the MySQL backup suffix_ MySQL backup restore
MySQL advanced (Advanced) SQL statement
Istio部署:快速上手微服务,
Data dimensionality reduction factor analysis
Memory management of C
How to set priorities in C language? Elaborate on C language priorities
R language uses econcharts package to create microeconomic or macroeconomic maps, and indifference function to visualize indifference curve
Py之interpret:interpret的简介、安装、案例应用之详细攻略
Qpropertyanimation use and toast case list in QT
Reading notes of "the way to clean structure" (Part 2)
Solution: vs2017 cannot open the source file stdio h main. H header document [easy to understand]