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 |
谁来证明一下,次数 k 和 k%8 效果是一样的。加上了这个优化,就过了,没想通如何证明。 代码如下: #include <iostream> #include <algorithm> #include <vector> using namespace std; int main(int argc,char* argv[]) { int i,j,sum; bool flag; for(int count=1;;count++) { flag = false; vector<int> datapool; sum = 0; for(i=1;i<=6;i++) { cin>>j; flag = flag || j!=0 ; j = j % 8; //这里! for(;j>0;j--) { datapool.push_back(i); sum += i; } } if(!flag) break; int half = sum /2; if(sum % 2 != 0) { flag = false; } else { do { int partsum = 0; for(i=0;i<datapool.size();i++) { if(partsum==half) { flag = true; break; } else { partsum += datapool[i]; if(partsum>half) { flag = false; break; } else continue; } } if(flag) break; }while(next_permutation(datapool.begin(),datapool.end())); } if(flag) { cout<<"Collection #"<<count<<":"<<endl; cout<<"Can be divided."<<endl<<endl; } else { cout<<"Collection #"<<count<<":"<<endl; cout<<"Can't be divided."<<endl<<endl; } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator