Cod sursa(job #1380164)

Utilizator AlxzAlex Cremeneanu Alxz Data 6 martie 2015 22:31:56
Problema Fractal Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fractal.in");
ofstream fout("fractal.out");
int k,x,y,i,nod,mij,z,o;
int main()
{
    fin >>k>>x>>y;
    z=k;
    for(i=1;i<=z;i++)
    {
        mij=1<<(k-1);
        if (x<=mij&&y<=mij)//sectiunea 1
        {
            o=x;
            x=y;
            y=o;
        }
        else
            if(x>mij&&y<=mij)//sectiunea 2
            {
                nod+=3*mij*mij;
                x=x-mij;
            }
            else
                if(x<=mij&&y>mij)//sectiunea 3
                {
                    nod+=mij*mij;
                    o=x;
                    x=2*mij-y+1;
                    y=mij-o+1;
                }
                else//sectiunea 4
                {
                    nod+=2*mij*mij;
                    x=x-mij;
                    y=y-mij;
                }
                k--;
    }
    fout << nod;
    return 0;
}