Cod sursa(job #782765)

Utilizator repp4raduRadu-Andrei Szasz repp4radu Data 29 august 2012 21:50:41
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <fstream>

using namespace std;

int parcurgere(int k, int x, int y)
{
    if(k == 1)
    {
        if(x == 1)
        {
            if(y == 1) return 0;
            else return 3;
        }
        if(x == 2)
        {
            if(y == 1) return 1;
            else return 2;
        }
    }
    if(x <= (1 << (k - 1)))
    {
        if(y <= (1 << (k - 1)))
            return parcurgere(k - 1, y, x);
        else
            return 3 * (1 << (2 * (k - 1))) + parcurgere(k - 1, (1 << k) - y + 1, (1 << (k - 1)) - x + 1);
    }
    else
    {
        if(y <= (1 << (k - 1)))
            return (1 << (2 * (k - 1))) + parcurgere(k - 1, x - (1 << (k - 1)), y);
        else
            return 2 * (1 << (2 * (k - 1))) + parcurgere(k - 1, x - (1 << (k - 1)), y - (1 << (k - 1)));
    }
}

int main()
{
    int n, x, y;
    ifstream in("fractal.in");
    in>>n>>y>>x; in.close();
    ofstream out("fractal.out");
    out<<parcurgere(n, x, y); out.close();
    return 0;
}