Pagini recente » Cod sursa (job #631051) | Cod sursa (job #3175432) | Cod sursa (job #3202498) | Cod sursa (job #1161207) | Cod sursa (job #468169)
Cod sursa(job #468169)
#include <cstdio>
#include <iostream>
using namespace std;
int x, y, k;
long long dim[15];
long long REZ = 0;
void calc_dim()
{
for(int i = 1 ; i < 15 ; i++)
dim[i] = 4 * dim[i - 1] + 3;
}
void rotire_1()
{
int x2, y2;
x2 = (1<<(k - 1)) - y + 1;
y2 = x;
x = x2;
y = y2;
x = (1<<(k - 1)) - x + 1;
}
void rotire_4()
{
int x2, y2;
x2 = y;
y2 = (1<<(k - 1)) - x + 1;
x = x2;
y = y2;
x = (1<<(k - 1)) - x + 1;
}
void impartire()
{
if(y <= 1<<(k - 1) && x <= 1<<(k - 1))
rotire_1();
else if(y > 1<<(k - 1) && x <= 1<<(k - 1))
{
REZ += dim[k - 1] + 1;
y -= 1<<(k - 1);
}
else if(y <= 1<<(k - 1) && x > 1<<(k - 1))
{
REZ += 3 *(dim[k - 1] + 1);
x -= 1<<(k - 1);
rotire_4();
}
else if(y > 1<<(k - 1) && x > 1<<(k - 1))
{
REZ += 2 *(dim[k - 1] + 1);
y -= 1<<(k - 1);
x -= 1<<(k - 1);
}
}
int main()
{
freopen("fractal.in", "r", stdin);
freopen("fractal.out", "w", stdout);
cin >> k >> x >> y;
calc_dim();
while(k)
{
impartire();
k--;
}
printf("%d\n", REZ);
return 0;
}