Cod sursa(job #1880339)

Utilizator buzandanBuzan Dan Alexandru buzandan Data 15 februarie 2017 18:10:23
Problema Fractal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <fstream>
#include <iostream>
using namespace std;

ifstream fin("fractal.in");
ofstream fout("fractal.out");
int k,x,y;
long long a[16];
int main()
{
    fin >> k >> x >> y;
    a[1] = 3;
    for(int i = 2; i <= k; i++)
        a[i] = 4 * a[i - 1] + 3;
    int m {1};
    for(int i = 1; i <= k; i++)
        m *= 2;

    long long pasi {0};
    while(k)
    {
        m /= 2;
        if(x <= m &&  y <= m)
        {
            k--;
            int aux = x;
            x = y;
            y = aux;
        continue;
        }
        if(x > m  && y <= m )
        {
            pasi += a[--k];
            x -= m;
            continue;
        }
        if(x > m  && y > m )
         {
            pasi += 2*a[--k];
            x -= m;
            y -= m;
            continue;
         }
         if(x <= m && y > m)
        {
            pasi += 3*a[--k];
            int aux = x;
            x = 2*m - y + 1;
            y = m - aux + 1;
        }
    }
    fout << pasi << ' ';

}