Cod sursa(job #628037)

Utilizator kis_lorikis levente lorand kis_lori Data 31 octombrie 2011 14:45:10
Problema Fractal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
#include <iomanip>
#include <math.h>

using namespace std;

fstream fin("fractal.in",ios::in);
fstream fout("fractal.out",ios::out);

int calc(int k, int x, int y)
{
  if (k==1) 
    switch (x*10+y){
      case 11: return 0;
      case 21: return 1;
      case 22: return 2;
      case 12: return 3;
    }
  if ((x<=k)&&(y<=k)) return calc(k/2, y, x);
  if ((x>k)&&(y<=k)) return 2*k+calc(k/2, x-k, y);
  if ((x>k)&&(y>k))  return 4*k+calc(k/2, x-k, y-k);
  if ((x<=k)&&(y>k)) return 6*k+calc(k/2, 2*k-y+1, k-x+1);
}

int main()
{
  int n,x,y,k=1,i;
  fin>>n>>x>>y;
  for (i=1;i<=n-1;i++) k*=2;
  fout<<calc(k,y,x);
  fin.close(); fout.close();
  return 0;
}