Cod sursa(job #1832238)

Utilizator Marius7122FMI Ciltea Marian Marius7122 Data 19 decembrie 2016 17:27:43
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <stdio.h>
long p2[16],l[16],x,y;
int k;


int cadr(int k,long x,long y)
{
    k--;
    if(x<=p2[k])
    {
        if(y<=p2[k])
            return 1;
        return 2;
    }
    if(y<=p2[k])
        return 4;
    return 3;
}
long DivImp(int k,long x,long y)
{
    if(k==1)
        return cadr(k,x,y)-1;

    int c;
    c=cadr(k,x,y);
    switch(c)
    {
        case 1:
            return DivImp(k-1,y,x);
        case 2:
            return l[k-1]+1+DivImp(k-1,x,y-p2[k-1]);
        case 3:
            return 2*l[k-1]+2+DivImp(k-1,x-p2[k-1],y-p2[k-1]);
        case 4:
            return 3*l[k-1]+3+DivImp(k-1,p2[k-1]-y+1,p2[k]-x+1);
    }
}

int main()
{
    fscanf(fopen("fractal.in","r"),"%d%ld%ld",&k,&x,&y);
    p2[0]=1;
    for(int i=1;i<=15;i++)
    {
        p2[i]=p2[i-1]*2;
        l[i]=l[i-1]*4+3;
    }
    fprintf(fopen("fractal.out","w"),"%ld",DivImp(k,x,y));

    return 0;
}