Cod sursa(job #591971)

Utilizator rudarelLup Ionut rudarel Data 26 mai 2011 09:28:52
Problema Fractal Scor 70
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.74 kb
var f:text;
    k,x,y,nr,aux,i,sol:longint;

begin
 assign(f,'fractal.in');reset(f);
 readln(f,k,x,y);
 close(f);
 assign(f,'fractal.out');rewrite(f);
 nr:=1;
 for i:=1 to k do
  nr:=nr*2;
 repeat
  nr:=nr div 2;
  if x>nr then
   if y<=nr then
    begin
     dec(x,nr);
     sol:=sol+3*nr*nr;
    end
    else
     begin
      dec(x,nr);
      dec(y,nr);
      sol:=sol+2*nr*nr;
     end
   else
    if y>nr then
     begin
      dec(y,nr);
      sol:=sol+nr*nr;
     end
     else
      begin
       aux:=x;
       x:=y;
       y:=aux;
      end;
 until nr<=2;
 if (x=2) and (y=1) then
  inc(sol,3);
 if (x=2) and (y=2) then
  inc(sol,2);
 if (x=1) and (y=2) then
  inc(sol,1);
 writeln(f,sol);
 close(f);
end.