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

Re:那位大牛帮我看一下,到底错在哪里?

Posted by 200892458 at 2009-04-24 21:15:04 on Problem 1014
In Reply To:那位大牛帮我看一下,到底错在哪里? Posted by:200892458 at 2009-04-24 20:58:12
> #include<stdio.h>
> #include<memory.h>
> bool hasvalue[60001];
> bool divide(int *nums,int sum)
> {
> 	int temp,i,j,k,max=0;
> 	hasvalue[0]=true;
> 	for(i=0;i<6;i++)
> 	{
> 		if(nums[i])
> 		{
> 		  for(j=max;j>=0;j--)
>           if(hasvalue[j])
> 		  {
>              temp=j;
> 		     if((temp+i+1>sum)||hasvalue[temp+i+1])
> 			    continue;
> 		     for(k=0;k<nums[i];k++)
> 			 {
> 			    temp+=i+1;
> 			    if(temp>sum)
> 				    break;
> 			    hasvalue[temp]=true;
> 			    if(temp==sum)
> 				    return true;
> 			 }
> 		     if(temp>max)
> 			     max=temp;
> 		     if(max>sum)
> 			     max=sum;
> 		  }
> 		}
> 	}
> 	if(hasvalue[sum])
> 		return true;
> 	return false;
> }
> 
> int main()
> {
> 	memset(hasvalue,false,sizeof(hasvalue));
> 	int nums[6]={0},i,sum=0,ncase=1;
> 	bool alleven;
> 	while(1)
> 	{
> 		sum=0;
> 		alleven=true;
>         for(i=0;i<6;i++)
> 		{
> 			scanf("%d",&nums[i]);
> 			sum+=nums[i]*(i+1);
> 			if(nums[i]%2!=0)
> 				alleven=false;
> 		}
> 		if(sum==0)
> 			return 0;
> 		printf("Collection #%d:\n",ncase++);
> 		if(alleven)
> 			printf("Can be divided.\n");
> 		else if(sum%2!=0)
> 			printf("Can't be divided.\n");
> 		else 
> 		{
> 			if(divide(nums,sum/2))
> 				printf("Can be divided.\n");
> 			else printf("Can't be divided.\n");
> 		}
> 		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