| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
flody就可以了!各位!#include <stdio.h>
#include <string.h>
#define maxn 40
double g[maxn][maxn];
int n;
char hash[maxn][40];
int position(char str[])
{
int pos;
for(pos=1;;pos++)
if(!strcmp(hash[pos],str))
return pos;
}
void flody()
{
int i,j,k;
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(g[i][j]<g[i][k]*g[k][j])
g[i][j]=g[i][k]*g[k][j];
}
int main()
{
char s[40],t[40];
double c;
int times=1,flag,i,m;
while(scanf("%d",&n)!=EOF&&n)
{
for(i=1;i<=n;i++)
scanf("%s",hash[i]);
memset(g,0,sizeof(g));
scanf("%d",&m);
while(m--)
{
scanf("%s %lf %s",s,&c,t);
g[position(s)][position(t)]=c;
}
flody();
flag=0;
for(i=1;i<=n;i++)
if(g[i][i]>1.0)
{
flag=1;
break;
}
if(flag)
printf("Case %d: Yes\n",times++);
else
printf("Case %d: No\n",times++);
getchar();
}
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator