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 |
TLE代码求修改#include<iostream> using namespace std; int a[7]; int sum; bool marked[60002]; bool notend() { sum=0; for(int i=1;i<7;i++) { scanf("%d",a+i); sum+=i*a[i]; } if(sum==0) return false; return true; } bool ismarked(int n) { if(marked[n]) return true; if(n<7) { if(a[n]) { marked[n]=true; a[n]--; return true; } return false; } for(int i=n/2;i>0;i--) { if(ismarked(i)&&ismarked(n-i)) { marked[n]=true; return true; } } return false; } bool dividable() { if(sum%2) return false; sum/=2; memset(marked,0,sizeof(bool)); if(ismarked(sum)) return true; return false; } int main() { int c=0; while(notend()) { cout<<"Collection #"<<++c<<":"<<endl; if(dividable()) cout<<"Can be divided."<<endl; else cout<<"Can't be divided."<<endl; cout<<endl; } return 0; } 例如这组测试数据就很慢:0 0 0 0 0 61 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator