Cod sursa(job #1843374)

Utilizator tifui.alexandruTifui Ioan Alexandru tifui.alexandru Data 8 ianuarie 2017 17:46:02
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

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

int fractal(int K, int X, int Y)
{
    int power = (1 << (K - 1));

    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 <= power && Y <= power)
        return fractal(K - 1, Y, X);

    if (X <= power && Y > power)
        return power * power + fractal(K - 1, X, Y - power);

    if (X > power && Y > power)
        return 2 * power * power + fractal(K - 1, X - power, Y - power);

    return 3 * power * power + fractal(K - 1, power - Y + 1, 2 * power - X + 1);
}


int main()
{
    int k, x, y;
    fin >> k >> x >> y;

    fout << fractal(k, x, y);

    return 0;
}