标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6360 Accepted Submission(s):
2939
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #define M 35 6 using namespace std; 7 double map[M][M]; 8 int n; 9 10 void floyd() //利用floyd算法计算最大赔率 11 { 12 int k,i,j; 13 for(k=1; k<=n; k++) 14 for(i=1; i<=n; i++) 15 for(j=1; j<=n; j++) 16 if(map[i][j]<map[i][k]*map[k][j]) 17 map[i][j]=map[i][k]*map[k][j]; 18 } 19 20 int main() 21 { 22 int m,i,j,w=1; 23 char s[M],str[M][M]; 24 while(~scanf("%d",&n)&&n) 25 { 26 for(i=1; i<=n; i++) 27 scanf("%s",str[i]); 28 for(i=1; i<=n; i++) 29 for(j=1; j<=n; j++) 30 { 31 if(i==j) map[i][j]=1; //因为是找最大的汇率,因此初始时本身转本身为1,其他转化为0 32 else map[i][j]=0; 33 } 34 scanf("%d",&m); 35 int a,b; 36 double c; 37 for(i=1; i<=m; i++) 38 { 39 scanf("%s",s); 40 for(a=1; a<=n; a++) //将其转化为map数组记录 41 if(!strcmp(s,str[a])) 42 break; 43 scanf("%lf",&c); 44 scanf("%s",s); 45 for(b=1; b<=n; b++) 46 if(!strcmp(s,str[b])) 47 break; 48 map[a][b]=c; 49 } 50 floyd(); 51 cout<<"Case "<<w++<<": "; 52 if(map[1][1]>1) 53 cout<<"Yes"<<endl; 54 else 55 cout<<"No"<<endl; 56 } 57 return 0; 58 }
标签:
原文地址:http://www.cnblogs.com/pshw/p/5375367.html