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 xuguangshengqq at 2007-01-10 17:57:15 on Problem 1011
In Reply To:谁能给些易错的数据呀!多谢了!!----以下是小弟的代码,欢迎来参考: Posted by:xuguangshengqq at 2007-01-10 17:16:11
> #include <iostream.h>
> #include <stdlib.h>
> #include <memory.h>
> #define maxn 70
> bool used[maxn];
> int p[maxn];
> int len,n,count = 0;
> 
> int compare(const void *a,const void *b){
> return (*(int *)a)-(*(int *)b);
> }
> 
> bool f1(int k);
> bool f2(int kk,int pos,int left);
> 
> void main(){
> int i = 0;
> int sum = 0;
> while(cin>>n&&n){
>    sum = 0;
>    for(i = 1;i<=n;i++){
>      cin>>p[i];
> 	 sum+= *(p+i);
>    }
>    qsort(p+1,n,sizeof(int),compare);
>    //for(i = 1;i<=n;i++){
>    //  cout<<p[i]<<" ";
>    //}cout<<endl;
>   len = p[n];
>   for(;len<=sum;len++){
>   if(sum%len)continue;
>   memset(used,false,maxn);
>   count = sum/len;
>   if(f1(1))break;
>   }
>   if(len>sum)cout<<sum<<endl;
>   else cout<<len<<endl; 
> 
> }
> 
> 
> }
> 
> 
> bool f1(int k){
> //	cout<<"f1 = "<<k<<endl;
> 	if(k==count)
> 	{
> 		//cout<<" len = "<<len<<"  搜索成功!!\n";
> 		return true;
> 	}
> 	else
> 	{
> 	  int i = 0;
> 	   for(i=n;i>=1;i--){
> 	     if(!used[i])break;
> 	   }
> 	   used[i] = 1;
>        if(f2(k,i,len-p[i])){f1(k+1);return true;}
> 	   else
> 	   {//cout<<" len = "<<len<<"  搜索失败!!\n";
> 		return false;
> 	   }
> 	}
> }
> 
> bool f2(int kk,int pos,int left)
> {   //cout<<"f2: kk = "<<kk<<", pos = "<<pos<<", left = "<<left<<endl;
> 	if(left == 0)
> 	{
> 	if(f1(kk+1))return true;
> 	}
> 
> 	else if(pos<=1){return false;}
> 	
> 	else{
> 		int i = 0;
> 	  for(i = pos-1;i>=1;i--){
> 		 if(!used[i]&&p[i]<=left)
> 		 {
> 		     used[i] = true;
> 		     if(f2(kk,i,left-p[i])) return true;
> 		     else{
> 			used[i] = false;
>             while((i-1)&&p[i-1]==p[i])i--;
> 			 }
> 		 }
> 	  }
> 	return false;
> 	}
> }

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