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

大牛 帮忙看看 或者给个测试数据也行 谢谢

Posted by shiweixiong at 2012-03-01 22:52:37 on Problem 2240
#include<stdio.h>
#include<string.h>

int main()
{  
	char str[35][100],a[100],b[100];
	int n,i,j,k,flag,m,x,y,count=0;
	double map[35][35],rates;
	while(scanf("%d",&n)!=EOF)
	{   
		if(n==0)break;
		count++;
	
		memset(map,0.0,sizeof(map));

		for(i=0;i<n;i++)
		{
			scanf("%s",str[i]);
			map[i][i]=1.0;
		}
		
		scanf("%d",&m);
		
		while(m--)
		{
			scanf("%s %lf %s",&a,&rates,&b);
			
			for(i=0;i<n;i++)
			{
				if(strcmp(str[i],a)==0)
				{
					x=i;
					
				}
				else if(strcmp(str[i],b)==0)
				{
					y=i;
					//break;
				}
				
			}
            map[x][y]=rates;
		}
     for(k=0;k<n;k++)
		for(i=0;i<n;i++)
		  for(j=0;j<n;j++)
			  if(map[i][k]*map[k][j]>map[i][j])
                  map[i][j]=map[i][k]*map[k][j];
	  flag=0;
	 for(i=0;i<n;i++)
	 {
		 if(map[i][i]>1.0)
		 {
		  flag=1;
		  break;
		 }
	 }
	 printf("Case %d: ",count);
	 if(flag==1)
		 printf("Yes");
	 else
		 printf("No");
	 printf("\n");
	}
	
	
	return 0;
} 

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