Cod sursa(job #972708)

Utilizator t.g.g.tt.g.g.t t.g.g.t Data 12 iulie 2013 14:49:34
Problema Fractal Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.04 kb
var k:byte;
    x,y,rs,t:longint;

begin
  assign(input,'fractal.in'); reset(input);
  readln(k,x,y);
  while k<>1 do
    begin
      if (x<=(1 shl (k-1))) and (y<=(1 shl (k-1))) then
        begin
          t:=x;
          x:=y;
          y:=t;
          k:=k-1;
        end else
      if (x<=(1 shl (k-1))) then
        begin
          rs:=rs+(1 shl (k-1))*(1 shl (k-1));
          y:=y-1 shl (k-1);
          k:=k-1;
        end else
      if (y<=(1 shl (k-1))) then
        begin
          rs:=rs+3*(1 shl (k-1))*(1 shl (k-1));
          x:=1 shl k-x+1; t:=x; x:=1 shl (k-1)-y+1;
          y:=t;
          k:=k-1;
        end else
        begin
          rs:=rs+2*(1 shl (k-1))*(1 shl (k-1));
          x:=x-1 shl (k-1);
          y:=y-1 shl (k-1);
          k:=k-1;
        end;
    end;
  if x=1 then
    begin
      if y=2 then rs:=rs+1;
    end else
    begin
      if y=1 then rs:=rs+3;
      if y=2 then rs:=rs+2;
    end;
  assign(output,'fractal.out'); rewrite(output);
  writeln(rs);
  close(output);
end.