Cod sursa(job #472668)

Utilizator daniel.dumitranDaniel Dumitran daniel.dumitran Data 26 iulie 2010 09:30:06
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <stdio.h>

int rec(int k, int x, int y) {
  printf("%d %d %d\n", k, x, y);
  if (!k) return 0;
  int new_k = k - 1;
  int s = 1 << new_k;
  bool up = y <= s;
  bool left = x <= s;
  
  if (!up) y -= s;
  if (!left) x -= s;

  if (up & left) return rec(new_k, y, x);
  else if (!up & left) return s * s + rec(new_k, x, y);
  else if (!up) return 2 * s * s + rec(new_k, x, y);
  else return 3 * s * s + rec(new_k, s + 1 - y, s + 1 - x);  
}

int main() {
  int k, x, y;
  fscanf(fopen("fractal.in", "rt"), "%d %d %d", &k, &x, &y);
  fprintf(fopen("fractal.out", "wt"), "%d\n", rec(k, x, y));
  return 0;
}