Pagini recente » Cod sursa (job #1640032) | Cod sursa (job #1696499) | Cod sursa (job #836652) | Cod sursa (job #561266) | Cod sursa (job #1880706)
#include <fstream>
using namespace std;
ifstream fi ("fractal.in");
ofstream fo ("fractal.out");
long long cadran,k,x,y,sol,c1,c2,c3,c4;
int def_cad(long long ordin,long long l,long long c )
{
ordin--;
if (l<=(1<<ordin) and c<=(1<<ordin)) return c1;
if (l>(1<<ordin) and c<=(1<<ordin)) return c2;
if (l>(1<<ordin) and c>(1<<ordin)) return c3;
if (l<=(1<<ordin) and c>(1<<ordin)) return c4;
}
void pozitionare()
{
int parte;
if (cadran==1)
{
swap (c2,c4);
if (c1==1) c1=c1;
else
{
x=x-(1<<k);
y=y-(1<<k);
}
}
if (cadran==2)
{
sol=sol+(1<<(2*k));
if (c2==2) x=x-(1<<k);
else y=y-(1<<k);
}
if (cadran==3)
{
sol=sol+2*(1<<(2*k));
if (c3==3)
{
x=x-(1<<k);
y=y-(1<<k);
}
}
if (cadran==4)
{
sol=sol+3*(1<<(2*k));
swap (c1,c3);
if (c4==4) y=y-(1<<k);
else x=x-(1<<k);
}
}
int main()
{
fi>>k>>y>>x;
c1=1;
c2=2;
c3=3;
c4=4;
while (k>0)
{
cadran=def_cad(k,x,y);
k--;
pozitionare();
}
fo<<sol;
return 0;
}