Pagini recente » Cod sursa (job #760251) | Cod sursa (job #357298) | Cod sursa (job #2178243) | Cod sursa (job #1577160) | Cod sursa (job #2739582)
#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");
int n;
pair<int, int> dest;
int dim;
int fractal(int dim, pair<int, int>& p)
{
int 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 % int(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 % int(lim);
if (p.x == 0)
p.x = lim;
p.y = p.y % int(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;
}