3 1 0.5 0.5 0.5 1 0.4 0.5 0.4 1 3 1 2 2 3 1 3
0.500 0.400 0.500
8600 | We have carefully selected several similar problems for you: 1217 1598 1142 1690 2544
floyd算法求最短路径
ACcode:
#pragma warning(disable:4786)//使命名长度不受限制 #pragma comment(linker, "/STACK:102400000,102400000")//手工开栈 #include <map> #include <set> #include <queue> #include <cmath> #include <stack> #include <cctype> #include <cstdio> #include <cstring> #include <stdlib.h> #include <iostream> #include <algorithm> #define rd(x) scanf("%d",&x) #define rd2(x,y) scanf("%d%d",&x,&y) #define rds(x) scanf("%s",x) #define rdc(x) scanf("%c",&x) #define ll long long int #define maxn 1005 #define mod 1000000007 #define INF 0x3f3f3f3f //int 最大值 #define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i) #define MT(x,i) memset(x,i,sizeof(x)) #define PI acos(-1.0) #define E exp(1) #define ex 1e-6 using namespace std; double dp[maxn][maxn]; int n,m; int main(){ while(rd(n)!=EOF){ FOR(i,1,n) FOR(j,1,n) scanf("%lf",&dp[i][j]); FOR(i,1,n) FOR(j,1,n) FOR(k,1,n){ if(dp[j][k]<dp[j][i]*dp[i][k]) dp[j][k]=dp[j][i]*dp[i][k]; } rd(m); int x,y; while(m--){ rd2(x,y); if(dp[x][y]<ex) printf("What a pity!\n"); else printf("%.3lf\n",dp[x][y]); } } return 0; } /* 3 1 0.5 0.5 0.5 1 0.4 0.5 0.4 1 3 1 2 2 3 1 3 */