Cod sursa(job #2644295)

Utilizator andu2006Alexandru Gheorghies andu2006 Data 24 august 2020 10:49:12
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda prbd2 Marime 0.92 kb
#include<bits/stdc++.h>

using namespace std;
ifstream fin("fractal.in");
ofstream fout("fractal.out");
const short NMAX = 3501;
int cnt(int k,int x,int y){
    if(k==1){
        if(x==1){
            if(y==1)
                return 0;
            else return 3;
        }
        else{
            if(y==1)
                return 1;
            else return 2;
        }
    }
    int size=(1<<k)/2,x1=x%size,y1=y%size;
    if(!x1) x1=size;
    if(!y1) y1=size;
    if(x<=size && y<=size){
        return cnt(k-1,y1,x1);
    }
    else if(x>size){
        return size*size*(1+(y>size))+cnt(k-1,x1,y1);
    }
    else{
        return size*size*3+cnt(k-1,size-y1+1,size-x1+1);
    }
}
int main()
{
    int k,x,y;
    fin>>k>>y>>x;
    /*for(int i=0;i<(1<<k);i++)
        for(int j=0;j<(1<<k);j++)
            fout<<cnt(k,i+1,j+1)<<" \n"[j==(1<<k)-1];
    */
    fout<<cnt(k,x,y);
    return 0;
}