Cod sursa(job #2014575)

Utilizator GoogalAbabei Daniel Googal Data 23 august 2017 22:33:01
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream in("fractal.in");
ofstream out("fractal.out");

int k, x, y;

long long solverec(int x, int y, int k){
  if(k < 0)
    return 0;
  else if(x <= (1 << k) && y <= (1 << k))
    return solverec(y, x, k - 1);
  else if(x <= (1 << k) && (1 << k) < y)
    return solverec(x, y - (1 << k), k - 1) + (1LL * (1 << (2 * k)));
  else if((1 << k) < x && (1 << k) < y)
    return solverec(x - (1 << k), y - (1 << k), k - 1) + 2 * (1LL * (1 << (2 * k)));
  else
    return solverec((1 << k) - y + 1, 2 * (1 << k) - x + 1, k - 1) + 3 * (1LL * (1 << (2 * k)));
}

int main()
{
  in >> k >> x >> y;
  out << solverec(x, y, k - 1);

  in.close();
  out.close();
  return 0;
}