Cod sursa(job #1596247)

Utilizator DeehoroEjkoliPop Darian DeehoroEjkoli Data 10 februarie 2016 21:13:45
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#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;
}