HDU 1596 find the safest road
The HDU Find
2023-09-11 14:15:28 时间
find the safest road
Time Limit: 5000ms
Memory Limit: 32768KB
This problem will be judged on HDU. Original ID: 159664-bit integer IO format: %I64d Java class name: Main
XX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每一条路有一个安全系数s,s是在 0 和 1 间的实数(包括0,1),一条从u 到 v 的通道P 的安全度为Safe(P) = s(e1)*s(e2)…*s(ek) e1,e2,ek是P 上的边 ,现在8600 想出去旅游,面对这这么多的路,他想找一条最安全的路。但是8600 的数学不好,想请你帮忙 ^_^
Input
输入包括多个测试实例,每个实例包括:
第一行:n。n表示城市的个数n<=1000;
接着是一个n*n的矩阵表示两个城市之间的安全系数,(0可以理解为那两个城市之间没有直接的通道)
接着是Q个8600要旅游的路线,每行有两个数字,表示8600所在的城市和要去的城市
第一行:n。n表示城市的个数n<=1000;
接着是一个n*n的矩阵表示两个城市之间的安全系数,(0可以理解为那两个城市之间没有直接的通道)
接着是Q个8600要旅游的路线,每行有两个数字,表示8600所在的城市和要去的城市
Output
如果86无法达到他的目的地,输出"What a pity!",
其他的输出这两个城市之间的最安全道路的安全系数,保留三位小数。
其他的输出这两个城市之间的最安全道路的安全系数,保留三位小数。
Sample Input
3 1 0.5 0.5 0.5 1 0.4 0.5 0.4 1 3 1 2 2 3 1 3
Sample Output
0.500 0.400 0.500
Source
解题:貌似用单源最短路路效率更高。Floyd险过。。。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 1010; 18 double mp[maxn][maxn]; 19 int n,m; 20 int main() { 21 int i,j,k; 22 while(~scanf("%d",&n)){ 23 for(i = 1; i <= n; i++){ 24 for(j = 1; j <= n; j++) 25 scanf("%lf",mp[i]+j); 26 } 27 for(k = 1; k <= n; k++){ 28 for(i = 1; i <= n; i++){ 29 for(j = 1; j <= n; j++){ 30 double ret = mp[i][k]*mp[k][j]; 31 if(ret > mp[i][j]) mp[i][j] = ret; 32 } 33 } 34 } 35 scanf("%d",&m); 36 for(k = 0; k < m; k++){ 37 scanf("%d %d",&i,&j); 38 if(mp[i][j] == 0) puts("What a pity!"); 39 else printf("%.3f\n",mp[i][j]); 40 } 41 } 42 return 0; 43 }
相关文章
- fatal: The upstream branch of your current branch does not match the name of your current branch
- 凤凰之谜卡背 new card back "secrets of the phoenix"
- Why would one use a third-party DI Container over the built-in ASP.NET Core DI Container?
- Updates to the Git Commit Graph Feature
- The property 'RowId' is part of the object's key information and cannot be modified.
- HDU 3861 The King’s Problem(强连通+二分图最小路径覆盖)
- Mac M1 clang: error: the clang compiler does not support 'faltivec'问题解决
- SQL Developer 连接 oracle数据库 报错 Io 异常 The Network Adapter could not establish the connection的三种解决方法
- HDU 5491 The Next
- HDU 3729 I'm Telling the Truth
- HDU 5542 The Battle of Chibi (离散化+树状数组优化DP)
- UVaLive 6680 Join the Conversation (DP)
- HDU 4126 Genghis Khan the Conqueror (树形DP+MST)
- HDU 3666 THE MATRIX PROBLEM (差分约束)
- HDU 4489 The King’s Ups and Downs (DP+数学计数)
- HDU 4355 Party All the Time (三分求极值)
- Introduces the basic structure of Android ActivityManagerService
- The difference between Virtual DOM and DOM
- 程序员2020年新书推荐之 《Coders: The Making of a New Tribe and the Remaking of the World》
- git---如何解决The authenticity of host can't be established.
- nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:37
- 金仓kingbase连接报错The authentication type 10 is not supported. Check that you have configured the sys_hba.conf file to include the client's IP address or subnet
- Unity 报错之 The type or namespace name ‘UI‘ does not exist in the namespace ‘UnityEngine‘
- hdu 4869 Turn the pokers 策略(组合数)
- HDU 1595 find the longest of the shortest
- hdu 1028 Sample Ignatius and the Princess III (母函数)
- hdu 2444 The Accomodation of Students (判断二分图,最大匹配)
- FreeMarker template error: The following has evaluated to null or missing
- 【bzoj3011】[Usaco2012 Dec]Running Away From the Barn 可并堆