Cod sursa(job #2510396)

Utilizator AlexandruabcdeDobleaga Alexandru Alexandruabcde Data 16 decembrie 2019 17:15:01
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>

using namespace std;

ifstream f ("fractal.in");
ofstream g ("fractal.out");

int Divide (int ord, int x, int y, int rez)
{
    int mij = 1 << (ord - 1);

    if (ord == 0)
        return rez;

    if (x <= mij && y <= mij)
    {
        return Divide(ord - 1, y, x, rez);
    }

    if (x <= mij && y > mij)
    {
        return Divide(ord - 1, 2 * mij + 1 - y, mij + 1 - x, rez + 3 * mij * mij);
    }

    if (x > mij && y <= mij)
    {
       return Divide(ord - 1, x - mij, y, rez + mij * mij);
    }

    if (x > mij && y > mij)
    {
        return Divide(ord - 1, x - mij, y - mij, rez + 2 * mij * mij);
    }
}

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

    f >> k;
	f >> y >> x;

	g << Divide(k, x, y, 0);
    return 0;
}