Pagini recente » Cod sursa (job #2223907) | Cod sursa (job #22412) | Cod sursa (job #2751817) | Cod sursa (job #2705907) | Cod sursa (job #2523604)
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
const string file = "fractal";
const ll INF = 9223372036854775807ll;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, inf = 2147483647;
int rec(int n, int x, int y)
{
if (n == 0)
return 0;
int step = 1<<(n-1);
if (x < step && y < step)
return rec(n-1, y, x);
if (x < step)
return rec(n-1, x, y-step)+3*(step*step);
if (y < step)
return rec(n-1, x-step, y)+(step*step);
return rec(n-1, step- (y-step), step-(x-step))+2*(step*step);
}
int main()
{
ifstream fin (file+".in");
ofstream fout (file+".out");
int n, x, y;
fin >> n >> x >> y;
swap(x, y);
--x, --y;
fout << rec(n, x, y) << "\n";
return 0;
}