Pagini recente » Cod sursa (job #1409923) | Cod sursa (job #2407289) | Cod sursa (job #2294468) | Cod sursa (job #771578) | Cod sursa (job #3338410)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream fin("fractal.in");
ofstream fout("fractal.out");
int K, x, y;
int f(int K, int x, int y) {
if (K == 0) return 0;
int dim = 1 << (K - 1);
if (x <= dim && y <= dim) {
return f(K - 1, y, x);
} else if (x > dim && y <= dim) {
return dim * dim + f(K - 1, x - dim, y);
} else if (x > dim && y > dim) {
return 2 * dim * dim + f(K - 1, x - dim, y - dim);
} else {
return 3 * dim * dim + f(K - 1, 2 * dim - y + 1, dim - x + 1);
}
}
int main()
{
fin >> K >> x >> y;
fout << f(K, y, x);
}