Cod sursa(job #2485780)

Utilizator adimiclaus15Miclaus Adrian Stefan adimiclaus15 Data 2 noiembrie 2019 01:06:35
Problema Fractal Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fractal.in");
ofstream g("fractal.out");
int Find(int k,int x,int y)
{
    ///cout<<x<<" "<<y<<"\n";
    if(k==1)
    {
        if(x==1 && y==1)
        {
            return 1;
        }
        if(x==2 && y==1)
        {
            return 2;
        }
        if(x==2 && y==2)
        {
            return 3;
        }
        if(x==1 && y==2)
        {
            return 4;
        }  
    }
    else
    {
        k--;
        int sz=(1<<k);
        int steps=(1<<(2*k));
        ///cout<<sz<<" ";
        ///cout<<x<<" "<<y<<" "<<sz<<"\n";
        if(x<=sz && y<=sz)
        {
            return Find(k,y,x);
        }
        else
        {
            if(x>sz && y<=sz)
            {
                return steps+Find(k,x-sz,y);
            }
            else
            {
                if(x>sz && y>sz)
                {
                    return steps+steps+Find(k,x-sz,y-sz);
                }
                else
                {
                    if(x<=sz && y>sz)
                    {
                         return steps+steps+steps+Find(k,2*sz-y+1,sz-x+1);
                    }
                }
            }
        }
    }
}
int main()
{
    int k,x,y;
    f>>k>>x>>y;
   /// cout<<k<<" "<<x<<" "<<y;
    cout<<Find(k,y,x)-1;
    return 0;
}