Cod sursa(job #2488975)

Utilizator cameliapatileaPatilea Catalina Camelia cameliapatilea Data 7 noiembrie 2019 20:42:32
Problema Fractal Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include<iostream>
#include<fstream>
#include<cstdio>
 
using namespace std;

ifstream f("fractal.in");
ofstream g("fractal.out");
 
int raspuns = 0;
 
void recursiv(int k, int x, int y)
{
    if (k != 0)
    {
        int mij = 1;
        for (int i = 1; i < k; i++)
            mij *= 2;

        if (mij < x && mij < y)
        {
            raspuns = raspuns + 2 * mij * mij;
            recursiv(k - 1, x - mij, y - mij);
        }
        if (mij >= x && mij >= y)
        {
            recursiv(k - 1, x, y);
        }
        if (mij < x && mij >= y)
        {
            raspuns = raspuns + mij * mij;
            recursiv(k - 1, x - mij, y);
        }
        if (mij >= x && mij < y)
        {
            raspuns = raspuns + 3 * mij * mij;
            recursiv(k - 1, mij * 2 - y + 1, mij - x + 1);
        }
    }
    return;
}
 
 
int main()
{
    int k, x, y;
    f >> k >> y >> x;
    recursiv(k, x, y);
    g << raspuns; 
    return 0;
}