标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 18408 | Accepted: 7796 |
Description
Input
Output
Sample Input
3 USDollar BritishPound FrenchFranc 3 USDollar 0.5 BritishPound BritishPound 10.0 FrenchFranc FrenchFranc 0.21 USDollar 3 USDollar BritishPound FrenchFranc 6 USDollar 0.5 BritishPound USDollar 4.9 FrenchFranc BritishPound 10.0 FrenchFranc BritishPound 1.99 USDollar FrenchFranc 0.09 BritishPound FrenchFranc 0.19 USDollar 0
Sample Output
Case 1: Yes Case 2: No
Source
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <map> using namespace std; map<string, int> ID; double dis[35][35]; int n, m; int main() { int kase = 0; while (scanf("%d", &n) == 1 && n) { string s, s1; ID.clear(); for (int i = 0; i < n; ++i) { cin >> s; ID[s] = i; } for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) dis[i][j] = 1.0; scanf("%d", &m); for (int i = 0; i < m; ++i) { double x; cin >> s >> x >> s1; int id1 = ID[s], id2 = ID[s1]; dis[id1][id2] = x; } for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) dis[i][j] = max(dis[i][j], dis[i][k] * dis[k][j]); bool flag = true; printf("Case %d: ", ++kase); for (int i = 0; i < n; ++i) if (dis[i][i] > 1) { flag = false; printf("Yes\n"); break; } if (flag) printf("No\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/albert7xie/p/4905518.html