Cod sursa(job #2632796)

Utilizator stefan.popescuPopescu Stefan stefan.popescu Data 4 iulie 2020 22:55:54
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream in ("fractal.in");
ofstream out("fractal.out");
int ordin, x, y, nrpasi[17];
int bk(int x, int y, int grad)
{
    if(grad==0) return 0;

    if(x<=(1<<(grad-1)))                ///jumatatea de sus
    {
        if(y<=(1<<(grad-1))) ///cadranul 1
        {
            //cout<<"1 ";
            return bk(y, x, grad-1);
        }
        else ///cadranul 2
        {
            //cout<<"2 ";
            return 3*nrpasi[grad-1]+3+bk(2*(1<<(grad-1))-y+1, (1<<(grad-1))-x+1, grad-1); ///ramane
        }
    }
    else                                ///jumatatea de jos
    {
        if(y<=(1<<(grad-1))) ///cadranul 3
        {
            //cout<<"3 ";
            return nrpasi[grad-1]+1+bk(x-(1<<(grad-1)), y, grad-1);
        }
        else ///cadranul 4
        {
            //cout<<"4 ";
            return 2*nrpasi[grad-1]+2+bk(x-(1<<(grad-1)), y-(1<<(grad-1)),  grad-1); ///ramane
        }
    }
}
int main()
{
    for(int i=1; i<=15; i++)
        nrpasi[i]=nrpasi[i-1]*4+3;
    in>>ordin>>y>>x;
    out<<bk(x, y, ordin);
    return 0;
}