Pagini recente » Cod sursa (job #355478) | Cod sursa (job #1844780) | Cod sursa (job #1733137) | Cod sursa (job #749355) | Cod sursa (job #863570)
Cod sursa(job #863570)
#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;
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;
}