Pagini recente » Cod sursa (job #2847432) | Cod sursa (job #1616325) | Cod sursa (job #1057070) | Cod sursa (job #1912430) | Cod sursa (job #1821171)
#include<fstream>
#include<string.h>
#include<ctype.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<array>
#include<deque>
#include<math.h>
#include<unordered_set>
#include<queue>
#include<functional>
#include<set>
#include<iomanip>
#include<bitset>
using namespace std;
long long nr,x,y,k,p2[20],i;
long long calc(int k, int x, int y)
{
if (k == 1)
{
if (x == 1 && y == 1)
return 0;
if (x == 2 && y == 1)
return 1;
if (x == 2 && y == 2)
return 2;
if (x == 1 && y == 2)
return 3;
}
else
if (x <= p2[k - 1] &&y <= p2[k - 1])
return calc(k - 1, y, x);
else
if (x >= p2[k-1] && y <= p2[k - 1])
return p2[2*(k - 1)] + calc(k - 1, x - p2[k - 1], y);
else
if (x<=k && y>=k)
return p2[2 * (k - 1)]*3+calc(k - 1, p2[k - 1]*2-y+1, p2[k - 1]-x+1);
else
return p2[2 * (k - 1)]*2+calc(k - 1, x - p2[k - 1], y - p2[k - 1]);
}
int main()
{
//ifstream f("file.in");
//ofstream g("file.out");
ifstream f("fractal.in");
ofstream g("fractal.out");
f >> k >> x >> y;
p2[0] = 1;
for (i = 1; i <= 19; i++)
p2[i] = p2[i - 1] * 2;
g<<calc(k+1, x, y);
return 0;
}