Cod sursa(job #1823777)

Utilizator ducu34Albastroiu Radu Gabriel ducu34 Data 6 decembrie 2016 20:23:25
Problema Fractal Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 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)
    {
        if (x == 1 && y == 1)
            return 0;
        if (x == 2 && y == 1)
            return 1;
        if (x == 2 && y == 2)
            return 2;
        if (x == 1 && y == 2)
            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;
}