Pagini recente » Cod sursa (job #2003975) | Cod sursa (job #680714) | Cod sursa (job #1297238) | Cod sursa (job #173385) | Cod sursa (job #2344487)
#include <fstream>
using namespace std;
int k, x, y, l, nr;
int main () {
ifstream fin ("fractal.in");
ofstream fout ("fractal.out");
fin>>k>>y>>x;
l=1<<k;
nr=0;
while (x>1 || y>1) {
l/=2;
if (x<=l && y<=l) {
swap(x, y);
}else if (x>l && y<=l) {
nr+=l*l;
x-=l;
} else if (x>l && y>l) {
nr+=2*l*l;
x-=l;
y-=l;
} else {
nr+=3*l*l;
y-=l;
if ((x>l/2 && y>l/2) || (x<=l/2 && y<=l/2)) {
x=l-x+1;
y=l-y+1;
swap(x, y);
}
}
}
fout<<nr;
return 0;
}