Cod sursa(job #2739586)

Utilizator bubblegumixUdrea Robert bubblegumix Data 8 aprilie 2021 21:05:41
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.24 kb
#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;
		long long a = lim - p.y + 1;
		long long b = lim - p.x + 1;
		p.x = a;
		p.y = b;
		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;
}