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

这道题太bt了

Posted by 8ab12097207 at 2009-07-27 16:59:07 on Problem 1029
WA了我一整天。。。。一道程序害的我好像做了两道题,早上的程序到下午的时候,被我全删了。。。。汗汗。。。


#include <stdio.h>
#include <string.h>
int id[105][1005],k;
char ch[105];
int falsecoin(int *a)
{
	int i,j,s1=0,s2=0;
	for(i=0;i<k;i++)
	{
		s1=0;
		s2=0;
		for(j=1;j<=id[i][0];j++)
			s1+=a[id[i][j]];
		for(j=id[i][0]+1;j<=2*id[i][0];j++)
			s2+=a[id[i][j]];
		if(s1==s2&&ch[i]=='='||s1>s2&&ch[i]=='>'||s1<s2&&ch[i]=='<')
			continue;
		else
			return 1;
		

	}
	return 0;
}
int main()
{
	int n,i,j,flag,w,l1,l2;
	int a[1005],b[1005];
//	freopen("duo1029.txt","r",stdin);
	while(scanf("%d%d",&n,&k)==2)
	{
		for(j=0;j<k;j++)
		{
			for(i=1,scanf("%d",&id[j][0]);i<=2*id[j][0];i++)
				scanf("%d",&id[j][i]);
			getchar();
			ch[j]=getchar();
		}
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(i=1;i<=n;i++)
			a[i]=2;
		flag=0;
		for(i=0;i<k;i++)
			if(ch[i]=='=')
			{
				for(j=1;j<=2*id[i][0];j++)
				{
					b[id[i][j]]=2;//作为dp的一个判断,当出现'='时,所有的硬币都为真.
				}
			}
		for(i=1;i<=n;i++)//遍历所有的硬币。1表示轻,2表示正常,3表示重了
			if(!b[i])
			{
				a[i]=1;
				l1=falsecoin(a);
				a[i]=3;
				l2=falsecoin(a);
				if(!l1||!l2)
				{
					flag++;
					w=i;
				}
				a[i]=2;
			}
		if(flag==1)
			printf("%d\n",w);
		else
			printf("0\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