Pagini recente » Cod sursa (job #2015039) | Cod sursa (job #2362469) | Cod sursa (job #728627) | Cod sursa (job #937656) | Cod sursa (job #739895)
Cod sursa(job #739895)
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stack>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string.h>
using namespace std;
#define INPUT "in.txt"
#define IN "fractal.in"
#define OUT "fractal.out"
int place(int k, int x, int y) {
int p = 1 << (k - 1);
if (x <= p) {
return (y <= p) ? 0 : 1;
}
return (y <= p) ? 3 : 2;
}
void sol() {
int k, x, y;
int total = 0;
int c = -1, p, z = 0, t = 0;
scanf("%d %d %d", &k, &x, &y);
for (int i = k; i >= 1; i--) {
p = 1 << i;
if (x > p) x -= p;
if (y > p) y -= p;
c = place(i, x, y);
if (z == 1) {
if (c % 2 == 1) {
c += 2;
c %= 4;
}
}
if (t == 1) {
if (c % 2 == 0) {
c += 2;
c %= 4;
}
}
if (c == 3) {
t++;
t %= 2;
}
if (c == 0) {
z++;
z %= 2;
}
total += c * (1 << (2 * i - 2));
}
printf("%d", total);
}
int main() {
#ifdef PADREATI
freopen(INPUT, "r", stdin);
#else
freopen(IN, "r", stdin);
freopen(OUT, "w", stdout);
#endif
sol();
return 0;
}