Cod sursa(job #2488617)

Utilizator richard26Francu Richard richard26 Data 7 noiembrie 2019 11:15:28
Problema Fractal Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <bits/stdc++.h>

using namespace std;

long long pw2[100];

int divide(int x, int y, int dim) {

    if (dim == 1) {
        if (x == 1 && y == 1) {
            return 0;
        } 

        if (x == 1 && y == 2) {
            return 3;
        }

        if (x == 2 && y == 1) {
            return 1;
        }

        if (x == 2 && y == 2) {
            return 2;
        }
    } else {

        dim--;
        if (x <= pw2[dim] && y <= pw2[dim] ) {

            return divide(y, x, dim);
        } 
        
        else if (x <= pw2[dim] && y > pw2[dim]) {
            return 3 * pw2[2 * dim] + divide(pw2[dim] - y  + pw2[dim] + 1, pw2[dim] - x + 1, dim);
        }

        else if (x > pw2[dim] && y <= pw2[dim]) {

            return pw2[2 * dim] + divide(x - pw2[dim], y, dim);
        }

        else if (x > pw2[dim] && y > pw2[dim]) {

            return 2 * pw2[2 * dim] + divide(x - pw2[dim], y - pw2[dim], dim);
        }
    }

    
    
}

int main()
{

    ifstream f("fractal.in");
    ofstream g("fractal.out");
    pw2[0] = 1;
    int x, y, k;

    
    cin >> k >> x >> y;
    for (int i = 1; i <= 2 * k; i++) {
        pw2[i] = 2 * pw2[i - 1];
        //cout << pw2[i] << endl;
    }
    cout << divide(x, y, k + 1);
}