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 lhzlucky at 2006-12-16 22:02:02 on Problem 1011
#include <iostream>
using namespace std;
int disk[65];
int maxv[65];
int dn,flag;
int compare(const void* a,const void* b)
{
    return *(int*)b - *(int*)a ;
}
void back(int rem,int n,int len)//rem:当前木棍剩余长度,n原始木棍数量,len原始木棍长度
{
   int i;
   for(i=0;i<dn&&!flag;i++)
   {
	   if(maxv[i]==0&&rem>=disk[i])
	   {
		   if(rem==disk[i])
		   {
               if(n<=2)
			   {
				   flag=1;return;
			   }
			   else
			   {
				   maxv[i]=1;
				   back(len,n-1,len);//return;
			   }
		   }
		   else
			    {
				   maxv[i]=1;
				   back(rem-disk[i],n,len);
			    }
	   }
   }
}
void main()
{
	int n,i,j,s,t,min=100,max=1;
	while(cin>>dn&&dn)
	{
		s=0;
		for(i=0;i<dn;i++)
		{
			cin>>disk[i];
			s+=disk[i];
		}
		qsort(disk,dn,sizeof(int),compare);
		for(i=disk[0];i<=s;i++)
		{
			if(s%i==0)
			{
				for(j=0;j<dn;j++)maxv[j]=0;
				flag=0;
				back(i,s/i,i);
				if(flag)break;
			}
		}
		cout<<i<<endl;
	}
}


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