Cod sursa(job #1350586)

Utilizator iuliatoth.Iulia Toth iuliatoth. Data 20 februarie 2015 20:47:55
Problema Fractal Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>
using namespace std;
int p[18];
int fractal(int k,int x,int y)
{
    if(x==1 && y==1) return 0;
    else if(x==1 && y==2) return 1;
    else if(x==2 && y==2) return 2;
    else if(x==2 && y==1) return 3;
    else
    {
        if(x<=p[k-1] && y<=p[k-1])
            return fractal(k-1,y,x);
        else if(x<=p[k-1] && y>p[k-1])
            return fractal(k-1,x,y-p[k-1]) + p[k-1]*p[k-1];
        else if(x>p[k-1] && y>p[k-1])
            return fractal(k-1,x-p[k-1],y-p[k-1]) + p[k]*p[k-1];
        else return fractal(k-1,p[k-1]-y+1,p[k]-x+1) + 3*p[k-1]*p[k-1];
    }
}
int main()
{
    ifstream f("fractal.in");
    ofstream g("fractal.out");
    int k,x,y;
    f>>k>>x>>y;
    p[0]=1;
    for(int i=1;i<=k;i++) p[i]=p[i-1]*2;
    int result=fractal(k,x,y);
    g<<result;
    f.close();
    g.close();
    return 0;
}