标签:lap one close clu man script 个数 gif pac
#include <iostream> #include <iomanip> #include <cstring> using namespace std; typedef long long LL; int visited[1005],n,q; double safety[1005][1005]; double dest[1005]; int main(){ // freopen("test.in","r",stdin); while (scanf("%d",&n) != EOF){ for (int i=1;i<=n;i++){ for (int j=1;j<=n;j++){ scanf("%lf",&safety[i][j]); } } scanf("%d",&q); for (int i=1;i<=q;i++){ int src,des; memset(visited,0,sizeof(visited)); memset(dest,0,sizeof(dest)); scanf("%d %d",&src,&des); for (int j=1;j<=n;j++){ dest[j] = safety[src][j]; } dest[src] = 1; visited[src] = 1; int finish = 0; while (!finish){ int maxi = 0; double maxdes = -1; for (int j=1;j<=n;j++){ // cout << dest[j] << " "; if (!visited[j] && dest[j] > maxdes){ maxi = j; maxdes = dest[j]; } } // cout << endl; if (maxi == 0){ finish = 1; break; } visited[maxi] = 1; for (int j=1;j<=n;j++){ if (!visited[j]){ dest[j] = max(dest[j],dest[maxi] * safety[maxi][j]); } } } if (dest[des] != 0) printf("%.3lf\n",dest[des]); else printf("What a pity!\n"); } } return 0; }
标签:lap one close clu man script 个数 gif pac
原文地址:http://www.cnblogs.com/ToTOrz/p/7284489.html