|
|
back to boardPlease , help me.My program got WA1,but answer in my computer is right. Here is my brutforce: #include <stdio.h> #include <iostream.h> #include <math.h> //typedef enum {true,false} bool; bool z[20]; long int a[20]; long int min,v1,v2,k,n,j,l,i; void incr() { int in; for (in = 0; in< 20 ; in++ ) { if (z[in]==false){z[in]=true;break;} else z[in]=false; return; } } int main(){ for (l=0;l<20;l++) z[l]=1; cin>>n; // long int i; for (i=0;i<n;i++) cin>>a[i]; min=100000; for (i=0;i<=1048575;i++) { incr(); v1=0;v2=0; for (j=0;j<20;j++) { if (z[j]) v1=v1+a[j]; else v2=v2+a[j]; if (fabs((double)(v1-v2))<min) min=fabs((double)(v1-v2));
} } cout<<(long int)min<<endl; return 0; } Re: Please , help me.My program got WA1,but answer in my computer is right. Your brute-force) function void incr() is wrong. try test: 5 3 2000 4 5 6 and this with other order: 5 2000 3 4 5 6 my brute-function is: int minn = 2000000000; void solve(int first, int h1) { ___if(first == n && minn > abs(sum - h1 - h1) ) ______minn = abs(sum - h1 - h1); ___for(int i = first; i < n; i++) ______solve( i + 1, h1 + a[i] ); } Good Luck!;) Edited by author 10.07.2008 12:55 Re: Please , help me.My program got WA1,but answer in my computer is right. I think just not use double. Re: Please , help me.My program got WA1,but answer in my computer is right. I think just not use double. Or change your code: cout << (long int)(min + 1e-6) << endl; |
|
|