Cod sursa(job #2625230)

Utilizator ioana0211Ioana Popa ioana0211 Data 5 iunie 2020 20:17:40
Problema Fractal Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream fin ("fractal.in");
ofstream fout ("fractal.out");
int ordin;
long long x, y;
long long pasi;
long long put;
long long fract (long long coordx, long long coordy)
{
    if(ordin==1)
    {
        if(coordx==2 && coordy==1) pasi++;
        else if(coordx==2 && coordy==2) pasi+=2;
        else if(coordx==1 && coordy==2) pasi+=3;
        return pasi;
    }
    ordin--;
    put/=2;
    if(coordx<=put && coordy<=put) //cadranul 1
    {
        fract(coordy, coordx);
    }
    else if(coordx>put && coordy<=put) // cadranul 2
    {
        pasi+=2*put;
        fract(coordx-put, coordy);
    }
    else if(coordx<=put && coordy>put) // cadranul 4
    {
        pasi+=6*put;
        fract(2*put-coordy+1, put+1-coordx);
    }
    else if(coordx>put && coordy>put) //cadranul 3
    {
        pasi+=4*put;
        fract(coordx-put, coordy-put);
    }
}
int main()
{
    fin>>ordin>>y>>x;
    put=1;
    for(int i=1; i<=ordin; i++)
        put*=2;
    fout<<fract(x, y);
    return 0;
}