Cod sursa(job #1800564)

Utilizator BLz0rDospra Cristian BLz0r Data 7 noiembrie 2016 21:32:27
Problema Fractal Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <fstream>
//#include <algorithm>
//#include <vector>
using namespace std;

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

int N, X, Y;
//vector<int> V;

void DEI(int K, int x, int y, long long pasi) {

    if (x == X && y == Y) {
        //V.push_back(pasi);
        //fout << X << ", " << Y << " => " << pasi << "\n";
        fout << pasi;
        return;
    }

    int pieces = (1 << (2 * K - 2));

    int lg = 1 << (K - 1);

    if (X < x + lg && Y < y + lg)
        DEI(K - 1, x, y, pasi + 0LL * pieces);

    else if (X >= x + lg && Y < y + lg)
        DEI(K - 1, x + lg, y, pasi + 1LL * pieces);

    else if (X >= x + lg && Y >= y + lg)
        DEI(K - 1, x + lg, y + lg, pasi + 2LL * pieces);

    else if (X < x + lg && Y >= y + lg)
        DEI(K - 1, x, y + lg, pasi + 3LL * pieces);
}

int main(){

    fin >> N >> Y >> X;

    /*for (int i = 1; i <= (1 << N); ++i)
        for (int j = 1; j <= (1 << N); ++j ) {
            X = i;
            Y = j;*/
            DEI(N, 1, 1, 0);

/*
    sort(V.begin(), V.end());

    vector<int> :: iterator it;

    for (it = V.begin(); it != V.end(); ++it)
        fout << *it << " ";
*/
    return 0;
}