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 |
那位大牛看看 错在哪 N多数据都能过 却WA#include <iostream> #include<algorithm> using namespace std; int arr[65]; bool flag[65]; int main() { int n ; while(cin>>n && n!=0) { int sum_len = 0; int max_len = 0; for (int i=1; i<n+1; i++) { flag[i] = 0; cin>>arr[i]; sum_len = sum_len +arr[i]; if(arr[i]>max_len) max_len = arr[i]; } sort(arr+1,arr+n+1); for(int i = max_len;i<sum_len+1 ;i++) { if(sum_len%i != 0) continue; int len = 0; for(int j = n;j>0;j--) { if(!flag[j]) { len = arr[j]; flag[j] = true; for(int k = j-1;k>0;k--) { if(!flag[k]) { len = len + arr[k]; if(k != 1&&len>i) { len = len - arr[k]; continue; } if(len == i) { flag[k] = true; break; } if(len<i) flag[k] = true; } else continue; } if( len>i) break; } else continue; } for(int t = 1;t<n+1;t++) { if(flag[t] == false) { for (int i=1; i<n+1; i++) flag[i] = 0; goto L; } } cout<<i<<endl; break; L:continue; } } return 0; } 速度啊,帮帮忙 我郁闷死了 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator