Pagini recente » Cod sursa (job #933912) | Cod sursa (job #1366509) | Cod sursa (job #1670182) | Cod sursa (job #1795604) | Cod sursa (job #228855)
Cod sursa(job #228855)
var k,x,y:longint;
f,g:text;
function rec(k,x,y:longint):longint;
var t,zone,x0,y0:longint;
begin
t:=1 shl (k-1);
if (x<=t) and (y<=t) then
zone:=0;
if (x<=t) and (y>t) then
zone:=3;
if (x>t) and (y<=t) then
zone:=1;
if (x>t) and (y>t) then
zone:=2;
if k=1 then begin
rec:=zone;
exit;
end;
x0:=x;
y0:=y;
case zone of
0: begin
y:=x0;
x:=y0;
rec:=rec(k-1,x,y);
end;
1: begin
x:=x0-t;
rec:=t*t+rec(k-1,x,y);
end;
2: begin
x:=x0-t;
y:=y0-t;
rec:=t*t*2+rec(k-1,x,y);
end;
3: begin
x:=2*t-y0+1;
y:=t-x0+1;
rec:=t*t*3+rec(k-1,x,y);
end;
end;
end;
begin
assign(f,'fractal.in'); reset(f);
assign(g,'fractal.out'); rewrite(g);
read(f,k,x,y);
writeln(g,rec(k+1,x,y));
close(f); close(g);
end.