Cod sursa(job #734722)

Utilizator TrixerAdrian Dinu Trixer Data 14 aprilie 2012 18:58:13
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <iostream>
#include <fstream>

using namespace std;

int Putere(int k)
{
    int i,x=1;
    for (i=1;i<=k;i++) x*=2;
    return x;
}

int Cadran(int k,int x,int y)
{
    int p;
    p=Putere(k-1);
    if (x<=p)
        {
            if (y<=p) return 0;
            else return 1;
        }
    else
        {
            if (y<=p) return 3;
            else return 2;
        }
}

int main()
{
int k,x,y,nr=0,i,c=-1,p,z=0,t=0;
ifstream f;
ofstream g;

    f.open("fractal.in");
    f>>k>>x>>y;
    f.close();

    for (i=k;i>=1;i--)
        {
            p=Putere(i);
            if (x>p) x-=p;
            if (y>p) y-=p;
            c=Cadran(i,x,y);
            cout<<c<<' ';
            if (z==1) {if (c==1) c=3;
                       else if (c==3) c=1;}
            if (t==1) {if (c==0) c=2;
                       else if (c==2) c=0;}
            if (c==3) {if (t==1) t=0;
                       else t=1;}
            if (c==0) {if (z==0) z=1;
                       else z=0;}
            nr+=c*Putere(2*i-2);
        }

    g.open("fractal.out");
    g<<nr;
    g.close();

return 0;
}