当前位置:网站首页>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;
}
边栏推荐
- Pytorch版本、CUDA版本与显卡驱动版本的对应关系
- What is the MySQL backup suffix_ MySQL backup restore
- Dictionaries
- NMF-matlab
- 程序猿入门攻略(十二)——数据的存储
- Watchful pioneer world outlook Architecture - (how does a good game come from)
- How to avoid duplicate data in gaobingfa?
- 数据湖(十二):Spark3.1.2与Iceberg0.12.1整合
- A4988 drive stepper motor "recommended collection"
- 452-strcpy、strcat、strcmp、strstr、strchr的实现
猜你喜欢
xml开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
MySQL function
Reading notes of "the way to clean structure" (Part 2)
Usage of ieda refactor
冒泡排序数组
PHP parser badminton reservation applet development requires online system
Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode
AcWing 340. 通信线路 题解(二分+双端队列BFS求最短路)
Thread application instance
高并发下如何避免产生重复数据?
随机推荐
R language uses econcharts package to create microeconomic or macroeconomic maps, and indifference function to visualize indifference curve
How to print mybats log plug-in using XML file
Py's interpret: a detailed introduction to interpret, installation, and case application
Postman下载安装
How to avoid duplicate data in gaobingfa?
AcWing 383. Sightseeing problem solution (shortest circuit)
多态的理解以及作用
AcWing 340. 通信线路 题解(二分+双端队列BFS求最短路)
安装单机redis详细教程
450-深信服面经1
AcWing 342. 道路与航线 题解 (最短路、拓扑排序)
Codeforces Round #802 (Div. 2) 纯补题
AcWing 1128. 信使 题解(最短路—Floyd)
AcWing 1137. 选择最佳线路 题解(最短路)
Golang并发编程——goroutine、channel、sync
SIFT feature point extraction "suggestions collection"
Machine learning notes - time series prediction research: monthly sales of French champagne
AcWing 1129. 热浪 题解(最短路—spfa)
Use cheat engine to modify money, life and stars in Kingdom rush
KT148A语音芯片ic的硬件设计注意事项