Cod sursa(job #1205338)

Utilizator tudi98Cozma Tudor tudi98 Data 6 iulie 2014 01:59:29
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.51 kb
#include <fstream>
using namespace std;

int u,d,l,r,x,y;

int solve(int k,int type){
    if(k==0) return 0;
    int mx=(u+d)/2;
    int my=(l+r)/2;
    if(x<=mx && y<=my){   //cadran 1
        d=mx,r=my;
        if(type==1)
            return solve(k-1,2);
        if(type==2)
            return solve(k-1,1);
        if(type==3)
            return solve(k-1,3)+(1<<(k*2))/2;
        return solve(k-1,4)+(1<<(k*2))/2;
    }
    else if(x>mx && y<=my){   //cadran 2
        u=mx+1,r=my;
        if(type==1)
            return solve(k-1,1)+(1<<(k*2))/4;
        if(type==2)
            return solve(k-1,4)+(1<<(k*2))/4*3;
        if(type==3)
            return solve(k-1,3)+(1<<(k*2))/4;
        return solve(k-1,2)+(1<<(k*2))/4*3;
    }
    else if(x>mx && y>my){     //cadran 3
        u=mx+1,l=my+1;
        if(type==1)
            return solve(k-1,1)+(1<<(k*2))/2;
        if(type==2)
            return solve(k-1,2)+(1<<(k*2))/2;
        if(type==3)
            return solve(k-1,4);
        return solve(k-1,3);
    }
    else{      //cadram 4
        d=mx,l=my+1;
        if(type==1)
            return solve(k-1,3)+(1<<(k*2))/4*3;
        if(type==2)
            return solve(k-1,2)+(1<<(k*2))/4;
        if(type==3)
            return solve(k-1,1)+(1<<(k*2))/4*3;
        return solve(k-1,4)+(1<<(k*2))/4;
    }
}

int main(){

    ifstream f("fractal.in");
    ofstream g("fractal.out");

    int k;
    f >> k >> y >> x;
    l=u=1;
    r=d=(1<<k);

    g << solve(k,1);
}