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 |
Re:help!!!In Reply To:help!!! Posted by:plumage at 2005-04-22 20:33:33 > #include<iostream.h> > #include<fstream.h> > > void main() > { > fstream fin("in.txt",ios::in||ios::out); > int i,j=0,can=0,k; > long half,temp; > long marbles[8]; > > int r[8]; > int t; > marbles[0]=0; > while(1) > { > ////input > fin>>marbles[1]>>marbles[2]>>marbles[3]>>marbles[4]>>marbles[5]>>marbles[6]; > // cin>>marbles[1]>>marbles[2]>>marbles[3]>>marbles[4]>>marbles[5]>>marbles[6]; > > ////judge whether go on by input > if(marbles[1]==0 && marbles[2]==0 && marbles[3]==0 && marbles[4]==0 && marbles[5]==0 && marbles[6]==0) > break; > half=0; > can=0; > > j++; //time of case > > for(i=1;i<=6;i++) > { > marbles[i]=marbles[i]%2; > marbles[i]*=i;//store the resting > r[7-i]=marbles[i]; > half+=marbles[i]; > } > > > if((half%2)==0)//half*2==0 > { > half/=2;//half the rest of dividing > > for(i=1;i<=6;i++)//whether can find value "half" by added the value of r[] > { > if(r[i]==0) > continue; > > t=1; > marbles[t]=i;//record the path > temp=half-r[i]; > > k=i; > if(temp>=0) > { > if(temp==0)//end > { > can=1; > break; > } > > for(k+=1;k<=6;k++) > if(r[k]!=0) > break; > > > if(k<6) > k++;//next item > else > break; > > while(1) > { > if(k<=6) > { > temp-=r[k]; > > if(temp>=0) > { > if(temp==0) > { > can=1; > break;//? > } > t++; > marbles[t]=k; > } > else > temp+=r[k]; > > k++; > } > else//k>6 > { > // k=1+marbles[t]; > > k=marbles[t]; //the last has recorded > > temp+=r[k]; //back one step > t--; > k++; > // k=marbles[t]+1; > > if(marbles[t]==i) > break; > > }//end else > }//end while > } > }//end for > }//end (half%2)==0 > > if(can==1) > { > if(j!=1) > cout<<endl; > cout<<"Collection #"<<j<<":"<<endl; > cout<<"Can be divided."<<endl; > > } > else > { > if(j!=1) > cout<<endl; > > cout<<"Collection #"<<j<<":"<<endl; > cout<<"Can't be divided."<<endl; > } > /**/ > } > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator