Cod sursa(job #1992010)

Utilizator richieYRichie Yeung richieY Data 19 iunie 2017 00:38:12
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <fstream>
#include <iostream>

using namespace std;

int fractal(int k, int x, int y) {
    
    int pw = 1 << (k-1);
    
    if(k == 1) {
        if(x == 1 && y == 1) {
            return 0;
        } else if(x == 1 && y == 2) {
            return 1;
        } else if(x == 2 && y == 2) {
            return 2;   
        } else {
            return 3;
        }
    } else {
        if(x > pw && y > pw) {
            return 2*pw*pw + fractal(k-1, x - pw, y - pw);
        } else if(x > pw && y <= pw) {
            return 3*pw*pw + fractal(k-1, pw - y + 1, 2*pw - x + 1);
        } else if (x <= pw && y > pw) {
            return pw*pw + fractal(k-1, x, y - pw);
        } else {
            return fractal(k-1, y, x);
        }
    }
    
    return 6;
}

int main() {
    int k, x, y;
    
    ifstream fin("fractal.in");
    fin >> k >> x >> y;

    ofstream fout("fractal.out");
    fout << fractal(k, x, y);
    return 0;
}