Pagini recente » Cod sursa (job #1756251) | Cod sursa (job #698309) | Cod sursa (job #2698440) | Cod sursa (job #1785078) | Cod sursa (job #475558)
Cod sursa(job #475558)
#include<iostream>
#include<fstream>
using namespace std;
int k, x, y;
long pasi;
ifstream fin("fractal.in");
ofstream fout("fractal.out");
void calculeaza( int k, int x, int y )
{
int aux;
if ( k > 0 )
{
if ( ( x >= 1 && x <= 1<<(k-1) ) && ( y >= 1 && y <= 1<<(k-1) ) ) //cadran 1
aux = x, x = y, y = aux;
else
if ( ( x >= 1 && x <= 1<<(k-1) ) && ( y >= (1<<(k-1))+1 && y <= 1<<k ) ) //cadran 2
{
y = y - (1<<(k-1));
pasi += 1<<(2*k-2);
}
else
if ( ( x >= (1<<(k-1))+1 && x <= 1<<k ) && ( y >= (1<<(k-1))+1 && y <= 1<<k ) ) //cadran 3
{
x = x - (1<<(k-1));
y = y - (1<<(k-1));
pasi += 2 * 1<<(2*k-2);
}
else //cadran 4
{
x = x - (1<<(k-1));
aux = x;
x = (1<<(k-1)) - y + 1;
y = (1<<(k-1)) - aux + 1;
pasi += 3 * 1<<(2*k-2);
}
calculeaza(k-1, x, y);
}
}
int main()
{
fin >> k >> x >> y;
calculeaza(k,x,y);
fout << pasi << endl;
return 0;
}