Cod sursa(job #2145152)

Utilizator ZanoxNonea Victor Zanox Data 27 februarie 2018 10:02:11
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <iostream>

using namespace std;

int rec_f(int x,int y,int l)
{
    //cout<<x<<' '<<y<<' '<<l<<'\n';
    if(l==2)
    {
        if(x==1&&y==1)return 0;
        if(x==1&&y==2)return 3;
        if(x==2&&y==1)return 1;
        if(x==2&&y==2)return 2;
    }
    int h=l/2;
    if(x<=h&&y<=h)return rec_f(y,x,h); //secondary diagonal flip (by reversed axis)
    if(x<=h&&y>h)return h*h*3+rec_f(h-(y-h)+1,h-x+1,h); //principal diagonal flip
    if(x>h&&y<=h)return h*h+rec_f(x-h,y,h);
    return h*h*2+rec_f(x-h,y-h,h);
}

int main()
{
    fstream fin("fractal.in",ios::in),fout("fractal.out",ios::out);
    int x,y,k;
    fin>>k>>x>>y;
    //cout<<x<<' '<<y<<"\n\n";
    fout<<rec_f(y,x,1<<k);
}