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 |
WA了N次 可是试了discuss中所有数据都没问题 大牛路过帮忙看下··不胜感激啊····· #include <iostream> using namespace std; int marbles[6]; void check(int ave) { int i,j; int temp = 0; for(i = 5; i >= 0; i--) { if(marbles[i] == 0) continue; temp += marbles[i] * (i+1); if(temp == ave) break; else if(temp > ave) //主要处理大于平均值的情况 { temp -= marbles[i] * (i+1); if(marbles[i] == 1) //只有一个值的话就不用处理了 continue; else { for(j = marbles[i] - 1; j >= 0; j--) { //每次减少一个,测试是否满足条件 temp += j * (i+1); if(temp == ave) break; if(temp > ave) temp -= j * (i+1); } } } else continue; } if(temp == ave) cout<<"Can be divided."<<endl<<endl; else cout<<"Can't be divided."<<endl<<endl; } int main() { int i,j,count = 0; int sum; while(1) { count++; sum = 0; j = 0; for(i=0; i<6; i++) { cin>>marbles[i]; sum += marbles[i] * (i+1); if(marbles[i] == 0) j++; } if(j == 6) break; cout<<"Collection #"<<count<<":"<<endl; if(sum%2 == 0) check(sum/2); else cout<<"Can't be divided."<<endl<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator