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

Who know test 1?
Posted by Element 20 Jun 2009 06:41
var
   x:array[1..20] of integer;
   y:array[1..20] of longint;
   min,s:longint;
   n,i,v:longint;
procedure outit;
var i:integer;
    s,c:longint;
begin
   s:=0;
   for i:=1 to n do
    inc(s,x[i]*y[i]);
   c:=v-s;
   if c>s then  s:=c-s else s:=s-c;
   if s<min then min:=s;
end;
procedure search(k:longint);
var i:integer;
begin
   if k>n then begin outit;exit;end;
   for i:=0 to 1 do
         begin x[k]:=i;search(k+1);end;
end;
begin
   readln(n);
   min:=0;
   v:=0;
   for i:=1 to n do read(y[i]);
   for i:=1 to n do begin min:=min+y[i]; end;
   v:=min;
   search(1);
   writeln(min);
end.

I think I'm right.
Re: Who know test 1?
Posted by lwyzdxh 25 Apr 2010 19:09
program ural1005;
var
    a:array[1..20]of boolean;
    w:array[1..20]of longint;
    i,j,k,n,m:longint;
function dif:longint;
var diff:longint;
begin
    diff:=0;
    for i:=1 to n do
        if a[i] then inc(diff,w[i]) else dec(diff,w[i]);
    exit(diff);
end;
procedure dfs(i:longint);
begin
    if i>n then
        begin
            if abs(dif)<m then m:=abs(dif);
            exit;
        end;
    a[i]:=true;
    dfs(i+1);
    a[i]:=false;
    dfs(i+1);
end;
begin
    readln(n);
    for i:=1 to n do
        readln(w[i]);
    m:=maxlongint;
    a[1]:=true;
    dfs(2);
    writeln(m);
end.
Me too
Re: Who know test 1?
Posted by Kuzmichev_dima 6 May 2010 22:51
not readln(w[i]); but read(w[i]);
I had this mistake at the first time (because of spaces between numbers)