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

Show all messages Hide all messages

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;
}
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
I think just not use double.
I think just not use double.

Or

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