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

一次写好就AC了 0MS 自己都不敢相信 谁挑挑错

Posted by mlion at 2009-11-01 16:07:03 on Problem 1014
#include "iostream"
using namespace std;
int arr[6];
int value;

bool find(int curvalue)
{
	int num=0;
if(curvalue>value)
	return false;
if(curvalue==value)
   return true;
for(int i=5;i>-1;i--)
{
	if(arr[i]!=0)
	{
	if(((i+1))>value)
		continue;
	else
	{
		arr[i]--;
		num=curvalue+i+1;
		if(find(num))
			return true;
		else
			arr[i]++;
	}

	}
}
return false;
}


int main(int argc, char* argv[])
{
	int n=0;
	while(true)
	{
		int sum=0;
		n++;
		for(int i=0;i<6;i++)
		{
			cin>>arr[i];
			sum+=arr[i]*(i+1);
		}
		if(!sum)
			break;
		value=sum/2;
        if(sum%2||(value%2==1)&&arr[0]==0&&arr[2]==0&&arr[4]==0||!find(0))
		{
			cout<<"Collection #"<<n<<":"<<endl;
			cout<<"Can't be divided."<<endl;
			cout<<endl;
			continue;
		}
		if(find(0))
		{
			cout<<"Collection #"<<n<<":"<<endl;
			cout<<"Can be divided."<<endl;
			cout<<endl;
			continue;
		}


	}

	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