Cod sursa(job #2269004)

Utilizator radugheoRadu Mihai Gheorghe radugheo Data 25 octombrie 2018 16:56:00
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>

using namespace std;

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

int drum, k, x, y;

void solve (int k, int x, int y){
    int n;
    if (k){
        k--;
        n = (1<<k);
        if (x <= n && y <= n){ // este in primul cadran (stanga sus)
            solve (k, y, x); // rotesc cu -90*
        }
        else if (x > n && y <= n){ //este in al doilea cadran (stanga jos)
            drum += n*n;
            solve (k, x - n, y);
        }
        else if (x > n && y > n){ //este in al treilea cadran (dreapta jos)
            drum += 2*n*n;
            solve (k, x - n, y - n);
        }
        else if (x <= n && y > n){ //este in al patrulea cadran (dreapta sus)
            drum += 3*n*n;
            solve (k, 2*n - y + 1, n - x + 1); // rotesc cu 90*
        }
    }
}
int main(){
    fin >> k >> x >> y;
    swap(x, y);
    solve (k, x, y);
    fout << drum;
    return 0;
}