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 |
why RE!#include <iostream.h> #include <memory.h> //#include <fstream.h> #include <math.h> int a[45001][20]; int used[45001]; int d[101],n,cha,half,r,s,result,sum; void set(int aa,int bb); void set2(int index); void main() { int i,j,min=4555555; //ifstream fin("in.txt"); //fin>>n; cin>>n; sum = 0; for(i=1;i<=n;i++) { //fin>>d[i]; cin>>d[i]; if(min>d[i]) min = d[i]; sum+=d[i]; } /*Input is over!!*/ memset(a,0,sizeof(a)); memset(used,0,sizeof(used)); half = sum/2; r = n/2; cha = 20000055; s = n - r; for(i=1;i<=n;i++) { set2(d[i]); for(j=1;j<=sum;j++) { if(used[j]!=0&&j!=d[i]) { set(d[i],d[j]); } } } if(result>(sum-result)) cout<<(sum-result)<<" "<<result<<endl; else cout<<result<<" "<<(sum-result)<<endl; return; } void set(int aa,int bb) { int i,j,k; int temp; for(i=1;i<=used[aa];i++) { for(j=1;j<=used[bb];j++) { temp = a[aa][i]+a[bb][j]; for(k=1;k<=used[aa+bb];k++) { if(a[aa+bb][k]==temp)break; } if(k==(used[aa+bb]+1)) { used[aa+bb]+=1; a[aa+bb][k] = temp; if((temp==r||temp==s)&&cha>abs(2*(aa+bb)-sum)) { cha = abs(2*(aa+bb)-sum); result = aa+bb; } } } } } void set2(int index) { used[index]++; a[index][used[index]] = 1; if((n==2||n==3)&&cha>abs(2*index-sum)) { cha = abs(2*index-sum); result = index; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator