Pagini recente » Cod sursa (job #623945) | Cod sursa (job #1100066) | Cod sursa (job #1516844) | Cod sursa (job #2345976) | Cod sursa (job #1596247)
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("fractal.in");
ofstream fout("fractal.out");
int k, x, y;
int hilbert(int k, int x, int y) {
if (k == 0)
return 0;
int pivot = round(pow(2, k - 1));
if (x <= pivot and y <= pivot)
return hilbert(k - 1, y, x);
if (x > pivot and y <= pivot)
return round(pow(pivot, 2)) + hilbert(k - 1, x - pivot, y);
if (x > pivot and y > pivot)
return round(pow(pivot, 2)) * 2 + hilbert(k - 1, x - pivot, y - pivot);
if (x <= pivot and y > pivot)
return round(pow(pivot, 2)) * 3 + hilbert(k - 1, pivot + 1 - (y - pivot), pivot + 1 - x);
}
void read_input() {
fin >> k >> y >> x;
fout << hilbert(k, x, y);
}
int main()
{
read_input();
return 0;
}