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:WA了50次终于过了啊!In Reply To:WA了50次终于过了啊! Posted by:mightyvoice at 2009-03-20 23:48:58 > 把一个边界条件写到了后面一点的位置,网上所有的数据全部过了还是WA,郁闷了一天啊,最后绝望的试着把if(sum<0) return(false)写在前面了一点就过了,那个激动啊!感谢网上大牛们的数据。特此贴代码庆祝我逃离苦海,0ms的感觉好啊, 没有加%30也过了。 > > #include <cstdlib> > #include <iostream> > > using namespace std; > > int a[3001][7],n; > > void input() > { int i,j; > for(i=1;i<=1001;i++) > { for(j=1;j<=6;j++) cin>>a[i][j]; > if(a[i][1]==0&&a[i][2]==0&&a[i][3]==0&&a[i][4]==0&&a[i][5]==0&&a[i][6]==0) break; > for(j=1;j<=6;j++) a[i][j]=a[i][j]%30; > } > if(i==1) n=1; > else > n=i; > } > > bool exist(int j,int sum,int i) > { int k,l; > if(sum==0) return(true); > if(sum<0) return(false); > else{ if(j==6) > { if(a[i][j]!=0&&sum%6==0&&sum/6<=a[i][j]) return(true); > else return(false); > } > else { > for(l=j+1;l<=6;l++) if(a[i][l]!=0) break; > if(l>6) > { if(sum%j==0&&sum/j<=a[i][j]) return(true); > else return(false); > } > else for(k=0;k<=a[i][j];k++) if(exist(l,sum-k*j,i)) return(true); > } > return(false); > } > } > > int main(int argc, char *argv[]) > { int i,sum,j,k,l; > input(); > if(n==1) cout<<"Collection #"<<n<<":"<<endl<<"Can't be divided."<<endl<<endl; > else{ > n--; > for(i=1;i<=n;i++) > { sum=0; > for(j=1;j<=6;j++) sum+=a[i][j]*j; > if(sum%2==1) > { cout<<"Collection #"<<i<<":"<<endl<<"Can't be divided."<<endl<<endl; > continue; > } > else { sum=sum/2; > for(j=1;j<=6;j++) if(a[i][j]!=0) break; > if(exist(j,sum,i)) > cout<<"Collection #"<<i<<":"<<endl<<"Can be divided."<<endl; > else > cout<<"Collection #"<<i<<":"<<endl<<"Can't be divided."<<endl; > } > cout<<endl; > } > } > system("PAUSE"); > return EXIT_SUCCESS; > } > 汗,50次 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator