ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1005. Stone Pile

Please , help me.My program got WA1,but answer in my computer is right.
Posted by ENick(TNU) 24 Jun 2008 15:05
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.
Posted by -AlexandeR- (TNU) 10 Jul 2008 12:53
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.
Posted by Chmel_Tolstiy 10 Jul 2008 13:03
I think just not use double.
Re: Please , help me.My program got WA1,but answer in my computer is right.
Posted by Chmel_Tolstiy 10 Jul 2008 13:06
I think just not use double.

Or

change your code:
cout << (long int)(min + 1e-6) << endl;