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

总是WA,有谁能给点变态数据?附代码……

Posted by erex at 2009-07-20 12:04:03 on Problem 2257
#include<stdio.h>
#include<string.h>
#define min(x,y) x<y?x:y
int t[22][22],T,a,b,tmp;
char name[22][12],str1[12],str2[12];

int n2i(char str[])
{
	int i;
	for(i=0;i<a;i++)
		if(!strcmp(str,name[i]))
			return i;
}

int main()
{
	int i,j,k,m;
	while(1)
	{
		scanf("%d%d",&a,&b);
		if(a==0&&b==0)break;
		for(i=0;i<a;i++)
			scanf("%s",name[i]);
		for(i=0;i<b;i++)
		{
			scanf("%s%s%d",str1,str2,&tmp);
			t[n2i(str1)][n2i(str2)]+=tmp;
		}
		for(i=0;i<a;i++)
			for(j=0;j<a;j++)
				for(k=0;k<a;k++)
				{
					m=min(t[j][k],t[k][i]);
					t[j][k]-=m;
					t[k][i]-=m;
					t[j][i]+=m;
				}
		for(i=0;i<a;i++)
		{
			for(j=0;j<a;j++)
				if(t[i][j]>0)
				{
					t[j][i]=-t[i][j];
					t[i][j]=0;
				}
		}
		printf("Case #%d\n",++T);
		for(i=0;i<a;i++)
		{
			for(j=0;j<a;j++)
				if(t[i][j])
				{
					printf("%s %s %d\n",name[i],name[j],-t[i][j]);
					t[i][j]=0;
				}
		}
		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