Cod sursa(job #2101537)

Utilizator i.uniodCaramida Iustina-Andreea i.uniod Data 7 ianuarie 2018 17:50:26
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fractal.in");
ofstream fout("fractal.out");
long int nr[20];

long int sol(long int k, long int x, long int y)
{
    long int noroi=1<<(k-1);
    if (k==1)
    {
        if(x==1)
            if(y==1) return 0;
            else return 3;
        if(x==2)
            if(y==1) return 1;
            else return 2;
    }
    if(x<=noroi&&y<=noroi)
        return sol(k-1,y,x);
    if(x<=noroi&&y>noroi)
        return 3*nr[k-1]+3+sol(k-1,noroi-(y-noroi)+1,noroi-x+1);
    if(x>noroi&&y<=noroi)
        return nr[k-1]+1+sol(k-1,x-noroi,y);
    return 2*nr[k-1]+2+sol(k-1,x-noroi,y-noroi);
}

int main()
{
    long int i,k,x,y;
    nr[1]=3;
    for (i=2; i<=15; i++)
        nr[i]=nr[i-1]*4+3;
    fin>>k>>y>>x;
    fout<<sol(k,x,y);
    return 0;
}