Cod sursa(job #1002906)

Utilizator Adrian1997Radulescu Adrian Adrian1997 Data 29 septembrie 2013 11:13:17
Problema Fractal Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <fstream>
using namespace std;
ifstream f("fractal.in");
ofstream g("fractal.out");
int n,x,y;
long long sol;

void rec(int a,int b,int d){
    if(x==a && y==b)
        return;
    if(d==1){
        sol++;
        return;
    }
    if(x<a+d/2 && y<b+d/2){
        //se afla in sectorul I
        rec(a,b,d/2);
        return;
    }
    else if(x<a+d/2 && y>=b+d/2){
        //se afla in sectorul II
        sol+=3*((d/2)*(d/2));
        rec(a,b+d/2,d/2);
        return;
    }
    else if(x>=a+d/2 && y<b+d/2){
        //se afla in sectorul III
        sol+=(d/2)*(d/2);
        rec(a+d/2,b,d/2);
        return;
    }
    else{
        //se afla in sectorul IV
        sol+=d*(d/2);
        rec(a+d/2,b+d/2,d/2);
        return;
    }
}

int main(void){
    register int i,j,d;

    f>>n>>x>>y;
    d=(1<<n);
    rec(1,1,d);
    g<<sol;
    return 0;
}