//2625082 2011-08-13 10:36:36 Accepted 1092 C 20 160 ylwh@Unknown
#include <stdio.h>
#include <string.h>
#define N 32
#define M 100
int main()
{
int n, m, ok;
double d[N][N], temp;
int i, j, k, t=0, flag;
char name[N][M], s1[M], s2[M];
while(scanf("%d", &n), n)
{
ok = 0;
t++;
for(i=1; i<=n; i++)
{
scanf("%s", name[i]);
for(j=1; j<=n; j++)
d[i][j] = 0.0;
d[i][i] = 1.0;
}
scanf("%d", &m);
while(m--)
{
flag = 0;
scanf("%s%lf%s", s1, &temp, s2);
for(i=1; i<=n && flag!=2; i++)
{
if(strcmp(s1, name[i]) == 0)//刚开始竟然把这里写错了,惭愧啊惭愧
{
j = i;
flag++;
}
if(strcmp(s2, name[i]) == 0)
{
k = i;
flag++;
}
}
d[j][k] = temp;
}
for(k=1; k<=n; k++)
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
{
temp = d[i][k] * d[k][j];
if(temp > d[i][j])//要找最大的
d[i][j] = temp;
}
for(i=1; i<=n; i++)
if(d[i][i] > 1)
{
ok = 1;
break;
}
printf("Case %d: ", t);
if(ok)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
ZOJ 1092 Arbitrage 【Floyd-Warshal】
最新推荐文章于 2023-02-06 12:51:22 发布