Cod sursa(job #952683)

Utilizator primulDarie Sergiu primul Data 23 mai 2013 20:00:36
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include<fstream>
#include<algorithm>
 
using namespace std;
 
int base[3][3];
 
int steps(int size, int x, int y){
  if(size == 1)
    return base[x][y];
 
  int lim = 1 << (size - 1);
  if(x <= lim && y <= lim){
    swap(x, y);
    return steps(size - 1, x, y);
  }
  if(x > lim && y <= lim){
    x -= lim;
    return steps(size - 1, x, y) + lim * lim;
  }
  if(x > lim && y > lim){
    x -= lim;
    y -= lim;
    return steps(size - 1, x, y) + 2 * lim * lim;
  }
  y -= lim;
  int aux = x;
  x = lim - y + 1;
  y = lim - aux + 1;
  return steps(size - 1, x, y) + 3 * lim * lim;
}
 
int main(){
  ifstream in("fractal.in");
  ofstream out("fractal.out");
 
  int k, x, y;
 
  base[1][1] = 0;
  base[2][1] = 1;
  base[2][2] = 2;
  base[1][2] = 3;
 
  in >> k >> x >> y;
  swap(x, y);
 
  out << steps(k, x, y);
 
  return 0;
}