Pagini recente » Cod sursa (job #2716442) | Cod sursa (job #1851916) | Cod sursa (job #662074) | Cod sursa (job #2641836) | Cod sursa (job #801452)
Cod sursa(job #801452)
#include<fstream>
using namespace std;
int k,x,y,v[20],s,i;
void T(int k,int x,int y)
{
if (k==0)
return;
int p=1 << (k-1);
if ((x<=p) && (y<=p))
T(k-1,y,x);
else if (y<=p)
{
s+=v[k-1]+1;
T(k-1,x-p,y);
}
else if (x<=p)
{
s+=3*v[k-1]+3;
T(k-1,2*p-y+1,p-x+1);
}
else
{
s+=2*v[k-1]+2;
T(k-1,x-p,y-p);
}
}
int main()
{
ifstream f("fractal.in");
ofstream g("fractal.out");
f >> k >> x >> y;
for (i=1;i<=k;i++)
v[i]=v[i-1]*4+3;
s=0;
T(k,y,x);
g << s;
}