Given the exchange rate of various currencies, you can switch between currencies to see if you can use some kind of exchange, which will make you end up with more money than you have just started, and of course the same currency.
If usually do the shortest path certainly do not know can use Floyd to do, I saw a paper before, said, the relaxation process of
D[V] < D[u] + W (v,u)
The plus can be extended to various forms of operation, then did not notice, thought should be no use, happened in this problem Floyd can also change the symbol. It's magical, remember, you might use it later.
#include <stdio.h> #include <string.h> int n,i,j,k,edges; int from,to; Double weight; int flag,start = 1; Double biao[31][31]; Char kindof[31][50]; Char t[50]; int find (char *a) {int i; for (i = 1; I <= N, i++) if (strcmp (a,kindof[i]) = = 0) return i;} int main (void) {while (s CANF ("%d", &n)! = EOF && N) {for (i = 1; i <=; i++) for (j = 1; J <=; j + +) Biao[i][j] = 0; for ( i = 1; I <= 30; i++) Biao[i][i] = 1; for (i = 1; I <= n; i++) scanf ("%s", Kindof[i]); scanf ("%d", &edges); for (i = 1; I <= edges; i++) {scanf ('%s ', t); from = find (t); scanf ("%lf%s", &weight,t); to = find (t); biao[from][t O] = weight; } for (k = 1; k <= N, k++) for (i = 1; I <= n; i++) for (j = 1; J <= N; j + +) if (Biao[i][j] < biao[i][k] * BIAO[K][J]) biao[i][j] = biao[i][k] * Biao[k][j]; printf ("Case%d:", start++); for (i = 1, flag = 0; I <= n; i++) if (Biao[i][i] > 1.0) {flag = 1;printf ("yes/n"); break;} if (!flag) printf ("no/ n "); } RETurn 0; }