Pagini recente » Cod sursa (job #53329) | Cod sursa (job #3234450) | Cod sursa (job #850742) | Cod sursa (job #2140284) | Cod sursa (job #952683)
Cod sursa(job #952683)
#include<fstream>
#include<algorithm>
using namespace std;
int base[3][3];
int steps(int size, int x, int y){
if(size == 1)
return base[x][y];
int lim = 1 << (size - 1);
if(x <= lim && y <= lim){
swap(x, y);
return steps(size - 1, x, y);
}
if(x > lim && y <= lim){
x -= lim;
return steps(size - 1, x, y) + lim * lim;
}
if(x > lim && y > lim){
x -= lim;
y -= lim;
return steps(size - 1, x, y) + 2 * lim * lim;
}
y -= lim;
int aux = x;
x = lim - y + 1;
y = lim - aux + 1;
return steps(size - 1, x, y) + 3 * lim * lim;
}
int main(){
ifstream in("fractal.in");
ofstream out("fractal.out");
int k, x, y;
base[1][1] = 0;
base[2][1] = 1;
base[2][2] = 2;
base[1][2] = 3;
in >> k >> x >> y;
swap(x, y);
out << steps(k, x, y);
return 0;
}