Pagini recente » Cod sursa (job #3002281) | Cod sursa (job #2599859) | Cod sursa (job #2990458) | Cod sursa (job #608779) | Cod sursa (job #2151670)
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <cstring>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int calculate(int n, int x, int y) {
if (n == 1) {
return 0;
} else {
int hn = n >> 1;
int sf = hn * hn - 1;
if (x <= hn) {
if (y <= hn) {
return calculate(hn, y, x);
} else {
y -= hn;
return 3 * sf + 3 + calculate(hn, hn - y + 1, hn - x + 1);
}
} else {
if (y <= hn) {
x -= hn;
return sf + 1 + calculate(hn, x, y);
} else {
x -= hn;
y -= hn;
return 2 * sf + 2 + calculate(hn, x, y);
}
}
}
return 0;
}
int main() {
ifstream fin("fractal.in");
ofstream fout("fractal.out");
int k, x, y;
fin >> k >> y >> x;
fout << calculate(1 << k, x, y);
return 0;
}