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 |
请指教?为什么老是错了?#include <iostream.h> int n[7]; int s[7]; int sum=0,solve=0,hx,i=0,num=0; void deal(int i) { int j,min; if(i==1) { if(hx<=n[1]) { solve=1;return; } } else { min=hx/i; if(n[i]<min) min=n[i]; for(j=0;j<=min;j++) { sum+=i*j; hx-=i*j; if(hx==s[i-1]) { solve=1;return; } if(hx<s[i-1]) deal(i-1); else { hx+=i*j;sum-=i*j; } } } } void main() { for(i=1;i<7;i++) { cin>>n[i]; solve+=i*n[i]; } while(solve!=0) { num++; s[6]=solve; solve=0; sum=0; s[1]=n[1]; for(i=2;i<6;i++) s[i]=s[i-1]+i*n[i]; if(s[6]%2==1) { cout<<"Collection #"<<num<<":"<<endl; cout<<"Can't be divided."<<endl<<endl; solve=0; for(i=1;i<7;i++) { cin>>n[i]; solve+=i*n[i]; } } else { hx=s[6]/2; deal(6); if(solve==1) { cout<<"Collection #"<<num<<":"<<endl; cout<<"Can be divided."<<endl<<endl; } else { cout<<"Collection #"<<num<<":"<<endl; cout<<"Can't be divided."<<endl<<endl; } solve=0; for(i=1;i<7;i++) { cin>>n[i]; solve+=i*n[i]; } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator