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:为什么是WRONG ANSWER!!!!!!!!!!!!!!!!!In Reply To:Re:为什么是WRONG ANSWER!!!!!!!!!!!!!!!!! Posted by:burningice at 2003-12-01 10:26:17 #include<iostream.h> bool divide(int const *); bool check(int const *,int,int); void main() { int i,marbles[7],w=0,k=0; bool ans; for(i=1;i<=6;i++) { cin>>marbles[i]; w=marbles[i]+w; } while(w!=0) { ans=divide(marbles); k++; if(ans==1) cout<<"Collection #"<<k<<":"<<endl<<"Can be divided."<<endl<<endl; else cout<<"Collection #"<<k<<":"<<endl<<"Can't be divided."<<endl<<endl; w=0; for(i=1;i<=6;i++) { cin>>marbles[i]; w=marbles[i]+w; } } } bool divide(int const *pm) { long total=0,oneget,left; int i; for(i=1;i<=6;i++) { total=total+(*(pm+i))*i; } if(total%2!=0) return 0; else { oneget=total/2; for(i=6;i>=1;i--) { left=oneget-(*(pm+i))*i; if(left>0) oneget=left; if(left==0) return 1; if(left<0) return check(pm,oneget,i); } } return 0; } bool check(int const *ppm,int remain,int i1) { int n; while((remain>0)&&(i1>=1)) { n=remain/i1; if(n<=*(ppm+i1)) { remain=remain-n*i1; i1--; } else { remain=remain-(*(ppm+i1))*i1; i1--; } } if(remain==0) return 1; else return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator