Cod sursa(job #986435)

Utilizator narcis_vsGemene Narcis - Gabriel narcis_vs Data 18 august 2013 19:14:25
Problema Fractal Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <fstream>
#include <cassert>
#define In "fractal.in"
#define Out "fractal.out"

using namespace std;
int nr[20];

inline int Div(int k,int x,int y)
{
    if(!k)
        return 0;
    ///prima regiune
    const int m = ( 1 << (k-1) );
    if(x<=m && y<=m)
        return Div(k-1,y,x);
    ///a 2-a regiune
    if(x>m&&y<=m)
        return nr[k-1] + 1 + Div(k-1,x-m,y);
    ///a 3-a regiune
    if(x>m && y>m)
        return 2*nr[k-1] + 2 + Div(k-1,x-m,y-m);
    return nr[k-1] + 3  +Div(k - 1, (1 << k) - y + 1,(1 << (k - 1) ) - x + 1);
}
int main()
{
    int k, x , y, i;
    ifstream f(In);
    f>>k>>x>>y;
    f.close();
    nr[1] = 3;
    for(i = 2;i < k; ++i)
        nr[i] = 4*nr[i-1]+3;
    swap(x,y);
    ofstream g(Out);
    g<<Div(k,x,y)<<"\n";
    g.close();
    return 0;
}