Cod sursa(job #1940487)

Utilizator LeVladzCiuperceanu Vlad LeVladz Data 26 martie 2017 17:13:14
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.33 kb
#include <fstream>

using namespace std;

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

int x, y, nextL, nextx, nexty, ordin, L, nr;

int main ()
{
    fin >> ordin >> y >> x;
    // cate puncte sunt pana in locul i,j din matricea ordin (4^ordin elemente)
    L = (1<<ordin);
    while (L != 1)
    {
        nextL = L/2;
        if (x <= nextL)
        {
            if (y <= nextL)
            {
                // stanga sus
                nextx = y;
                nexty = nextL-x+1;
                x = nextx;
                y = nexty;
                y = nextL-y+1;
            }
            else
            {
                // dreapta sus
                nr += 3*nextL*nextL;
                y -= nextL;
                nextx = nextL-y+1;
                nexty = x;
                x = nextx;
                y = nexty;
                y = nextL-y+1;
            }
        }
        else
        {
            if (y <= nextL)
            {
                // stanga jos
                nr += nextL*nextL;
                x -= nextL;
            }
            else
            {
                // dreapta jos
                nr += 2*nextL*nextL;
                x -= nextL;
                y -= nextL;
            }
        }
        L /= 2;
    }
    fout << nr;
    return 0;
}