当前位置:网站首页>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;
}
边栏推荐
- 函数高阶-柯里化实现
- Thread application instance
- 450 Shenxin Mianjing 1
- AcWing 1129. 热浪 题解(最短路—spfa)
- From 20s to 500ms, I used these three methods
- KS004 基于SSH通讯录系统设计与实现
- 搭建哨兵模式reids、redis从节点脱离哨兵集群
- Horizontal ultra vires and vertical ultra vires [easy to understand]
- 良心总结!Jupyter Notebook 从小白到高手,保姆教程来了!
- Watchful pioneer world outlook Architecture - (how does a good game come from)
猜你喜欢
数据湖(十二):Spark3.1.2与Iceberg0.12.1整合
MySQL function
Thread application instance
《重构:改善既有代码的设计》读书笔记(下)
Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode
450 Shenxin Mianjing 1
Introduction to mongodb chapter 03 basic concepts of mongodb
Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode
字典
AcWing 342. Road and route problem solving (shortest path, topological sorting)
随机推荐
Set up sentinel mode. Reids and redis leave the sentinel cluster from the node
MySQL表历史数据清理总结
Think about the huge changes caused by variables
程序猿入门攻略(十二)——数据的存储
Build a master-slave mode cluster redis
Gamefi chain game system development (NFT chain game development function) NFT chain game system development (gamefi chain game development source code)
KS004 基于SSH通讯录系统设计与实现
Detailed tutorial on installing stand-alone redis
中缀表达式转换为后缀表达式(C语言代码+详解)
股票证券公司排名,有安全保障吗
xml开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
Understanding and function of polymorphism
《代碼整潔之道》讀書筆記
Data dimensionality reduction principal component analysis
mysql函数
Qpropertyanimation use and toast case list in QT
golang:[]byte转string
AcWing 342. 道路与航线 题解 (最短路、拓扑排序)
Microservice technology - distributed global ID in high concurrency
Chapter 7 - class foundation