Pagini recente » Cod sursa (job #2799941) | Rating Vlad Prismareanu (Vlad_pris) | Cod sursa (job #681028) | Cod sursa (job #3175731) | Cod sursa (job #801451)
Cod sursa(job #801451)
#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,x,y);
else if (x<=p)
{
s+=v[k-1]+1;
T(k-1,x,y-p);
}
else if (y<=p)
{
s+=3*v[k-1]+3;
T(k-1,x-p,y);
}
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,x,y);
g << s;
}