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

Why system give me WA1?
Posted by krey 9 May 2010 00:43
my program variation:

#include <stdio.h>
#include <math.h>

int main()
{
    int nrstones, i, min, w1, w2;
    int *weights;

    scanf("%d", &nrstones);
    weights = new int[nrstones];
    for(i = 0; i < nrstones; i++)
    {
        scanf("%d", &weights[i]);
    }

    min = weights[0];

    int perm = 1 << nrstones;

    for(i = 0; i < perm; i++)
    {
        w1 = 0;
        w2 = 0;
        int j;
        for(j = 0; j < nrstones; j++)
        {
            if((i >> j) % 2 == 0)
                w1 += weights[j];
            else
                w2 += weights[j];
        }

        if(min > abs((double)w1 - w2))
        {
            min = abs((double)w1 - w2);
            if(min == 0)
            {
                printf("%d", min);
                return 0;
            }
        }
    }
    printf("%d", min);
    return 0;
}