Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

flody就可以了!各位!

Posted by chenxuan123456789 at 2012-08-10 10:12:41 on Problem 2240
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator