Cod sursa(job #2504889)

Utilizator MateiAruxandeiMateiStefan MateiAruxandei Data 5 decembrie 2019 18:33:23
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <fstream>

using namespace std;

ifstream fin("fractal.in");
ofstream fout("fractal.out");

void work(int k, int x, int y, int nrP){
    if(k == 1){
        if(x == 1 && y == 1)
            fout << nrP << '\n';
        if(x == 2 && y == 1)
            fout << nrP + 1 << '\n';
        if(x == 2 && y == 2)
            fout << nrP + 2 << '\n';
        if(x == 1 && y == 2)
            fout << nrP + 3 << '\n';
    }
    else {
        int lim = (1 << (k - 1));
        int add = lim * lim;
        if(x <= lim && y <= lim)
            work(k - 1, y, x, nrP);
        else if(x > lim && y <= lim)
            work(k - 1, x - lim, y, nrP + add);
        else if(x > lim && y > lim)
            work(k - 1, x - lim, y - lim, nrP + 2 * add);
        else
            work(k - 1, lim - (y - lim) + 1, lim - x + 1, nrP + 3 * add);
    }
}

int main()
{
    int k, x, y;
    fin >> k >> y >> x;

    work(k, x, y, 0);
    return 0;
}