当前位置:网站首页>AcWing 1126. 最小花费 题解(最短路—dijkstra)
AcWing 1126. 最小花费 题解(最短路—dijkstra)
2022-07-02 18:27:00 【乔大先生】
AcWing 1126. 最小花费
朴素版dijkstra算法求最短路,又熟悉了一遍模板,注意题意,需要将给出的值转化成折损率,之后套用最短路模型求出折损率之积最大的一条路的折损率之积(为什么要折损率之积最大见如下公式:)
#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; //特殊处理,将扣的钱直接转化为折损率,题意即转化成折损率成绩最大的一条路,还是最短路模型
g[a][b] = g[b][a] = max(g[a][b], z);
}
cin>>S>>T;
dijkstra();
printf("%.8lf\n", 100 / d[T]);
return 0;
}
边栏推荐
- Gstore weekly gstore source code analysis (4): black and white list configuration analysis of security mechanism
- LeetCode 0871. Minimum refueling times - similar to poj2431 jungle adventure
- A4988 drive stepper motor "recommended collection"
- mybatiesHelperPro工具必须的可以生成到对应项目文件夹下
- Tutorial (5.0) 09 Restful API * fortiedr * Fortinet network security expert NSE 5
- Thread application instance
- Use cheat engine to modify money, life and stars in Kingdom rush
- MySQL表历史数据清理总结
- Microservice technology - distributed global ID in high concurrency
- End-to-End Object Detection with Transformers(DETR)论文阅读与理解
猜你喜欢

mysql函数

Educational Codeforces Round 129 (Rated for Div. 2) 补题题解

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

Markdown basic grammar

安装单机redis详细教程

Usage of ieda refactor

Introduction to the paper | application of machine learning in database cardinality estimation

Introduction to the paper | analysis and criticism of using the pre training language model as a knowledge base

教程篇(5.0) 09. RESTful API * FortiEDR * Fortinet 网络安全专家 NSE 5

云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统
随机推荐
全志A33使用主线U-Boot
metric_ Logger urination
思考变量引起的巨大变化
Refactoring: improving the design of existing code (Part 1)
Codeworks 5 questions per day (1700 average) - day 4
Use cheat engine to modify money, life and stars in Kingdom rush
Digital scroll strip animation
Gamefi chain game system development (NFT chain game development function) NFT chain game system development (gamefi chain game development source code)
Tutorial (5.0) 09 Restful API * fortiedr * Fortinet network security expert NSE 5
AcWing 903. 昂贵的聘礼 题解(最短路—建图、dijkstra)
[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
Reading notes of code neatness
A4988驱动步进电机「建议收藏」
Quanzhi A33 uses mainline u-boot
Introduction to the paper | application of machine learning in database cardinality estimation
预处理和预处理宏
Excel finds the same value in a column, deletes the row or replaces it with a blank value
Mobile robot path planning: artificial potential field method [easy to understand]
Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
Develop fixed asset management system, what voice is used to develop fixed asset management system