Cod sursa(job #2270926)

Utilizator toadehuPuscasu Razvan Stefan toadehu Data 27 octombrie 2018 19:13:13
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <iostream>
#include <fstream>
using namespace std;
int k,n,x,y;
int solutie;
ifstream fin("fractal.in");
ofstream fout("fractal.out");
void fractal(int k, int x, int y) {
    if (k > 0) {
          k--;
            int n=(1<<k);
        if (x <= n && y <= n) {
            fractal(k , y, x);
        }
    else
        if (x > n && y <= n) {
           solutie += n*n;
            fractal(k , x - n, y);
        }
        else
        if (x <= n && y > n) {
            solutie += 3*n*n;
            fractal(k , 2*n + 1 - y, n - x + 1);
        }
        else
        if (x > n && y > n) {
            solutie += 2*n*n;
            fractal(k , x - n, y - n);
        }
    }
    return;
}
int main()
{
    fin>>k>>y>>x;

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