Cod sursa(job #1844345)

Utilizator narcios_neculaNarcis Necula narcios_necula Data 9 ianuarie 2017 22:20:35
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <fstream>
using namespace std;
ifstream f("fractal.in");
ofstream g("fractal.out");
int sol,k,x,y;
int fractal(int k, int x, int y)
{
    int p = 1 << k;
    p /= 2;
    if(k == 1 && x == 1 && y == 1)
        return 0;
    if(k == 1 && x == 1 && y == 2)
        return 1;
    if(k == 1 && x == 2 && y == 2)
        return 2;
    if(k == 1 && x == 2 && y == 1)
        return 3;
    if(x <= p && y <= p)
        return fractal(k - 1, y, x);
    if(x <= p && y > p)
        return p * p + fractal(k - 1, x, y - p);
    if(x > p && y > p)
        return 2 * p * p + fractal(k - 1, x - p, y - p);
    return 3 * p * p + fractal(k - 1, p - y + 1, 2 * p - x + 1);
}
int main()
{
    f >> k >> x >> y;
    sol = fractal(k, x, y);
    g << sol << '\n';
    return 0;
}