Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
各位大牛,小弟围成这代码若干天实在找不出WA的数据和原因啊,帮看下,小弟感激不尽#include <iostream> using namespace std; int input(int *predi,int &length,int &resum); void casum(int *predi,int length,int &leofsum,int *sum); int main() { int open=0; while(1) { int predi[2000]; int length; int resum; //prediving; if(input(predi,length,resum)==0) break; /* for(int i=1;i<=length;i++) cout<<predi[i]<<' '; cout<<endl; */ if(resum%2!=0||length==1) { ++open; cout<<"Collection #"<<open<<":\nCan't be divided."<<endl<<endl; continue; } /* for(int i=1;i<=length;i++) { cout<<predi[i]<<' '; } */ int leofsum; int sum[4000]; memset(sum,0,400*sizeof(int)); //lengthofsum; int canbe=0; casum(predi,length-1,leofsum,sum); //calculate sum; for(int i=1;i<=leofsum;++i) { if(resum/2==sum[i]) { ++open; cout<<"Collection #"<<open<<":\nCan be divided."<<endl<<endl; canbe=1; break; } } if(canbe==0) { ++open; cout<<"Collection #"<<open<<":\nCan't be divided."<<endl<<endl; } } } void casum(int *predi,int length,int &leofsum,int *sum) { if(length==1) { leofsum=1; sum[length]=predi[length]; return; } else //这里尝试用折半 { //int temp[200]; int *temp=new int[2000]; temp[1]=predi[length]; casum(predi,length-1,leofsum,sum); int i_1; //临时和的长度 for(i_1=1;i_1<=leofsum;) //对临时和的赋值 { ++i_1; temp[i_1]=predi[length]+sum[i_1-1]; //cout<<temp[i_1]<<' '; } //cout<<endl; for(int i=1;i<=i_1;++i) //将临时和加在末尾 { sum[0]=temp[i]; int j=1; //int j=leofsum; while(sum[0]>sum[j]&&j<=leofsum) { ++j; } if(sum[0]!=sum[j]) { int k=leofsum; while(k>=j) { sum[k+1]=sum[k]; --k; } sum[k+1]=sum[0]; ++leofsum; } } /* for(int i=1;i<=leofsum;i++) cout<<sum[i]<<' '; cout<<endl; */ delete[] temp; } } int input(int *predi,int &length,int &resum) { resum=0; int nofma=0; //NumofMarble; for(int vaofnum=1;vaofnum<=6;++vaofnum) {//Valueofnum int temp; cin>>temp; ///* if(temp>6&&temp%2==0) temp=6; else if(temp>6&&temp%2==1) temp=5; //*/ for(int i=1;i<=temp;++i) { nofma++; predi[nofma]=vaofnum; resum+=vaofnum; } } if(nofma==0) return 0; length=nofma; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator