Advertisement
a53

bluescreen

a53
Feb 27th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. const int MAX_N = 4005;
  7. double a[MAX_N];
  8. int low[MAX_N], high[MAX_N];
  9. double sol[2005][2005];
  10.  
  11. int main(){
  12.  
  13. freopen("bluescreen.in","r",stdin);
  14. freopen("bluescreen.out","w",stdout);
  15.  
  16. int N;
  17. double sum_initial = 0;
  18. scanf("%d\n",&N);
  19.  
  20. for(int i = 1;i <= N*2; ++i){
  21.  
  22. scanf("%lf ",&a[i]);
  23. low[i] = floor(a[i]);
  24. high[i] = ceil(a[i]);
  25. sum_initial += a[i];
  26. }
  27.  
  28. sol[0][0] = sum_initial;
  29. for(int i = 1; i <= N;++i){
  30.  
  31. sol[0][i] = sol[0][i-1] + high[i] - a[i];
  32. sol[i][0] = sol[i-1][0] + low[i] - a[i];
  33. }
  34. for(int i = 1; i <= N; ++i)
  35. for(int j = 1; j <= N; ++j){
  36.  
  37. double aux_low = sol[i-1][j] + low[i+j] - a[i+j];
  38. double aux_high = sol[i][j-1] + high[i+j] - a[i+j];
  39. if(fabs(sum_initial - aux_low) < fabs(sum_initial - aux_high))
  40. sol[i][j] = aux_low;
  41. else sol[i][j] = aux_high;
  42. }
  43.  
  44. printf("%.3lf",fabs(sum_initial - sol[N][N]));
  45.  
  46. fclose(stdin);
  47. fclose(stdout);
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement