Posted on 2008-03-23 13:09
superman 阅读(225)
评论(0) 编辑 收藏 引用 所属分类:
ZOJ
1 /* Accepted 1092 C++ 00:00.34 852K */
2 #include <string>
3 #include <iostream>
4
5 using namespace std;
6
7 int main()
8 {
9 int n, m, cases = 0;
10 string currency[30];
11 while((cin >> n) && n) {
12 for(int i = 0; i < n; i++)
13 cin >> currency[i];
14 cin >> m;
15
16 double f[30][30] = {0};
17 for(int i = 0; i < n; i++)
18 f[i][i] = 1.00;
19
20 string s, t;
21 double exchangeRate;
22 for(int k = 0; k < m; k++) {
23 cin >> s >> exchangeRate >> t;
24 int i, j;
25 for(i = 0; i < n; i++)
26 if(currency[i] == s)
27 break;
28 for(j = 0; j < n; j++)
29 if(currency[j] == t)
30 break;
31 f[i][j] = exchangeRate;
32 }
33
34 for(int k = 0; k < n; k++)
35 for(int i = 0; i < n; i++)
36 for(int j = 0; j < n; j++)
37 f[i][j] >?= f[i][k] * f[k][j];
38
39 bool Yes = 0;
40 for(int i = 0; i < n; i++)
41 if(f[i][i] > 1.00) {
42 Yes = 1;
43 break;
44 }
45 cases++;
46 cout << "Case " << cases << ": ";
47 if(Yes)
48 cout << "Yes" << endl;
49 else
50 cout << "No" << endl;
51 }
52 return 0;
53 }
54