Pagini recente » Cod sursa (job #211185) | Cod sursa (job #421334) | Cod sursa (job #2595970) | Cod sursa (job #2107559) | Cod sursa (job #2739584)
#include <iostream>
#include<fstream>
#include<cmath>
#include<math.h>
#define x first
#define y second
using namespace std;
ifstream f("fractal.in");
ofstream g("fractal.out");
long long n;
pair<long long, long long> dest;
long long dim;
long long fractal(long long dim, pair<long long, long long>& p)
{
long long lim= sqrt(dim / 4);
if (dim == 1)
return 1;
if (p.x >= 1 && p.x <= lim && p.y >= 1 && p.y <= lim)
{
swap(p.x, p.y);
return fractal(dim / 4, p);
}
if (p.x > lim && p.x <= 2* lim && p.y >= 1 && p.y <= lim)
{
p.x = p.x % lim;
if (p.x == 0)
p.x = lim;
return (dim / 4) + fractal(dim / 4, p);
}
if (p.x > lim && p.x <= 2* lim && p.y > lim && p.y <= 2* lim)
{
p.x = p.x % lim;
if (p.x == 0)
p.x = lim;
p.y = p.y % lim;
if (p.y == 0)
p.y = lim;
return 2*(dim / 4) + fractal(dim / 4, p);
}
if (p.x >= 1 && p.x <= lim && p.y > lim && p.y <= 2* lim)
{
p.y = p.y % lim;
if (p.y == 0)
p.y = lim;
p.x = lim - p.y + 1;
p.y = lim - p.x + 1;
return 3*(dim / 4) + fractal(dim / 4, p);
}
}
int main()
{
f >> n >> dest.y >> dest.x;
dim = pow(2, n);
g << fractal(dim * dim, dest) - 1;
return 0;
}