当前位置:网站首页>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;
}
边栏推荐
- Memory management of C
- Refactoring: improving the design of existing code (Part 2)
- How to avoid duplicate data in gaobingfa?
- Detailed tutorial on installing stand-alone redis
- 编写完10万行代码,我发了篇长文吐槽Rust
- 简书自动阅读
- Correspondence between pytoch version, CUDA version and graphics card driver version
- 解决方案:VS2017 无法打开源文件 stdio.h main.h 等头文件[通俗易懂]
- From 20s to 500ms, I used these three methods
- 《重构:改善既有代码的设计》读书笔记(下)
猜你喜欢

字典

AcWing 342. 道路与航线 题解 (最短路、拓扑排序)

450-深信服面经1

xml开发方式下AutowiredAnnotationBeanPostProcessor的注册时机

注解开发方式下AutowiredAnnotationBeanPostProcessor的注册时机

Windows2008R2 安装 PHP7.4.30 必须 LocalSystem 启动应用程序池 不然500错误 FastCGI 进程意外退出

SQLite 3.39.0 发布,支持右外连接和全外连接

How to avoid duplicate data in gaobingfa?

搭建主从模式集群redis
Bubble sort array
随机推荐
解决方案:VS2017 无法打开源文件 stdio.h main.h 等头文件[通俗易懂]
AcWing 343. Sorting problem solution (Floyd property realizes transitive closure)
Refactoring: improving the design of existing code (Part 1)
【pytorch学习笔记】Tensor
编写完10万行代码,我发了篇长文吐槽Rust
Introduction of Ethernet PHY layer chip lan8720a
Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
[pytorch learning notes] tensor
Solution: vs2017 cannot open the source file stdio h main. H header document [easy to understand]
Yes, that's it!
Refactoring: improving the design of existing code (Part 2)
PHP parser badminton reservation applet development requires online system
IEDA refactor的用法
KS004 基于SSH通讯录系统设计与实现
Chapter 7 - class foundation
Machine learning notes - time series prediction research: monthly sales of French champagne
SQLite 3.39.0 release supports right external connection and all external connection
Educational Codeforces Round 129 (Rated for Div. 2) 补题题解
守望先锋世界观架构 ——(一款好的游戏是怎么来的)
AcWing 1128. 信使 题解(最短路—Floyd)