Cod sursa(job #861157)

Utilizator sfarma_pietreOctavian Ganea sfarma_pietre Data 21 ianuarie 2013 01:17:54
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <map>
#include <stdlib.h>
#include <sstream>

#include <stdio.h>
#define PI 3.1415926535897932384626433832795

using namespace std;

int find_nr(int k, int x, int y) {
    if (k == 1) {
        if (x == 1 && y == 1) return 0;
        if (x == 1 && y == 2) return 1;
        if (x == 2 && y == 2) return 2;
        if (x == 2 && y == 1) return 3;
    }
    int half = 1 << (k-1);
    if (x <= half && y <= half) return half*half - 1 - find_nr(k-1, half - y + 1, x);
    if (x > half && y <= half) return 4*half*half - 1 - find_nr(k-1, y , 2*half + 1 - x) ;
    if (x <= half && y > half) return half*half + find_nr(k-1, x, y -half);
    if (x > half && y > half) return 2*half*half + find_nr(k-1, x - half, y - half);
    
}

int main() {
    freopen("fractal.in", "r", stdin);
    freopen("fractal.out", "w", stdout);

    int t = 1;
//    scanf("%d", &t);
    for (int w = 0; w < t; ++w){
        int k,x,y;
        scanf("%d%d%d", &k, &x, &y);
        printf("%d", find_nr(k,x,y));
        
    }
    return 0;
}