Cod sursa(job #2344057)

Utilizator mihaimodiMihai Modi mihaimodi Data 14 februarie 2019 18:22:02
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>
using namespace std;
ifstream fin("fractal.in");
ofstream fout("fractal.out");
int n,k,x,y,nr,L;
int main()
{
    fin>>k>>y>>x;
    L=1<<k;
    while(x>1||y>1)
    {
        L=L/2;
        if(x<=L&&y<=L)
            swap(x,y);
        else if(x>L&&y<=L)
        {
            nr+=L*L;
            x=x-L;
        }
        else if(x>L&&y>L)
        {
            nr+=2*L*L;
            y-=L;
            x-=L;
        }
        else
        {
            nr+=3*L*L;
            y=y-L;
            if(y<=L/2&&x<=L/2||x>L/2&&y>L/2)
            {
                x=L-x+1;
                y=L-y+1;
                swap(x,y);
            }
        }
    }
    fout<<nr;
    return 0;
}