Cod sursa(job #1219836)

Utilizator Cristian1997Vintur Cristian Cristian1997 Data 15 august 2014 13:32:08
Problema Fractal Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
using namespace std;
#include <fstream>
ifstream fin("fractal.in");
ofstream fout("fractal.out");


int main()
{
    int k, xf, yf, rez = 0, L;
    fin >> k >> xf >> yf;
    while(k > 0)
    {
        --k; L = (1 << k);
        if(yf <= L)
        {
            if(xf <= L) swap(xf, yf);
            else
            {
                rez += L * L;
                xf -= L;
            }
        }
        else
        {
            if(xf <= L) rez += 3 * L * L, yf = 2 * L - yf + 1, xf = L - xf + 1;
            else rez += 2 * L * L, xf -= L, yf -= L;
        }
    }
    fout << rez << '\n';
    return 0;
}