Cod sursa(job #2488433)

Utilizator LucianTLucian Trepteanu LucianT Data 6 noiembrie 2019 21:57:14
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>
using namespace std;

int n,x,y;

int divimp(int side,int x,int y){
    if(side==1){
        return 0;
    }

    int mij=side/2;
    if(x<mij && y<mij){
        return divimp(mij,y,x);
    } else if(x<mij && y>=mij){
        return mij*mij+divimp(mij,x,y-mij);
    } else if(x>=mij && y>=mij){
        return 2*mij*mij+divimp(mij,x-mij,y-mij);
    } else {
        return 3*mij*mij+divimp(mij,mij-y-1,2*mij-x-1);
    }
}

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

    f>>n>>x>>y;
    g<<divimp((1<<n),x-1,y-1);

    return 0;
}