Pagini recente » Monitorul de evaluare | Istoria paginii runda/strong_contest | Rating Costescu Ionut (w3.player) | Profil Xazzy | Cod sursa (job #2012347)
#include <stdio.h>
#include <stdlib.h>
int v[5],aux[5];
int main()
{
int k,x,y,l1,c1,l2,c2,nr,z,i;
freopen("fractal.in","r",stdin);
freopen("fractal.out","w",stdout);
scanf("%d%d%d",&k,&y,&x);
v[1]=1;
v[2]=2;
v[3]=3;
v[4]=4;
l1=1;
c1=1;
l2=1<<k;
c2=1<<k;
nr=0;
while(k)
{
if((l1+l2)/2>=x && (c1+c2)/2>=y) z=1;
if((l1+l2)/2<x && (c1+c2)/2>=y) z=2;
if((l1+l2)/2<x && (c1+c2)/2<y) z=3;
if((l1+l2)/2>=x && (c1+c2)/2<y) z=4;
if(z==1) l2=(l1+l2)/2,c2=(c1+c2)/2;
if(z==2) l1=(l1+l2)/2+1,c2=(c1+c2)/2;
if(z==3) l1=(l1+l2)/2+1,c1=(c1+c2)/2+1;
if(z==4) l2=(l1+l2)/2,c1=(c1+c2)/2+1;
for(i=1; i<=4 && v[i]!=z; i++);
nr+=(i-1)*(1<<(k-1))*(1<<(k-1));
switch(z)
{
case 1: aux[1]=v[1]; aux[2]=v[4]; aux[3]=v[3]; aux[4]=v[2]; break;
case 2: aux[1]=v[1]; aux[2]=v[2]; aux[3]=v[3]; aux[4]=v[4]; break;
case 3: aux[1]=v[1]; aux[2]=v[2]; aux[3]=v[3]; aux[4]=v[4]; break;
case 4: aux[1]=v[3]; aux[2]=v[2]; aux[3]=v[1]; aux[4]=v[4]; break;
}
for(i=1; i<=4; i++)
v[i]=aux[i],aux[i]=0;
k--;
}
printf("%d\n",nr);
return 0;
}