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 wqfcr at 2003-12-16 14:27:24 on Problem 1014
为什么总是错,请帮帮忙!
#include <iostream.h>
int n[7];
int s[7];
int sum=0,solve=0,hx,i=0,num=0;
void deal(int i)
{
	int j,min;
	if(i==1)
	{
		if(hx<=n[1])
		{
			solve=1;return;
		}
	}
	else
	{
		min=hx/i;
		if(n[i]<min)
			min=n[i];
		for(j=0;j<=min;j++)
		{
			sum+=i*j;
			hx-=i*j;
			if(hx==s[i-1])
			{
				solve=1;return;
			}
			if(hx<s[i-1])
				deal(i-1);
			else
			{
				hx+=i*j;sum-=i*j;
			}
		}
	}
}
void main()
{
	for(i=1;i<7;i++)
	{
		cin>>n[i];
	}
	while(n[1]!=0||n[2]!=0||n[3]!=0||n[4]!=0||n[5]!=0||n[6]!=0) 
	{
		s[6]=n[1]+2*n[2]+3*n[3]+4*n[4]+5*n[5]+6*n[6];
		num++;
		solve=0;
		sum=0;
		s[1]=n[1];
		for(i=2;i<6;i++)
			s[i]=s[i-1]+i*n[i];
		if(s[6]%2==1)
		{
			cout<<"Collection #"<<num<<":"<<endl;
			cout<<"Can't be divided."<<endl<<endl;
			for(i=1;i<7;i++)
			{
	        	cin>>n[i];
			}
		}
		else
		{
			hx=s[6]/2;
			deal(6);
	    	if(solve==1)
			{
 	    		cout<<"Collection #"<<num<<":"<<endl;
 		    	cout<<"Can be divided."<<endl<<endl;
			}
	    	else
			{
  	     		cout<<"Collection #"<<num<<":"<<endl;
 	    		cout<<"Can't be divided."<<endl<<endl;
			}
	    	for(i=1;i<7;i++)
			{
         		cin>>n[i];
			}
		}
	}
}
 

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