Cod sursa(job #2750354)

Utilizator bubblegumixUdrea Robert bubblegumix Data 10 mai 2021 21:45:04
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <iostream>
#include<fstream>
#include<cmath>
#include<math.h>
using namespace std;
ifstream f("fractal.in");
ofstream g("fractal.out");
int n;
int x, y;
long long dim;

long long fractal(long long dim, int x,int y)
{
	long long lim= sqrt(dim>>2);
	long long div = dim >> 2;
	if (dim == 1)
		return 1;
	if (x >= 1 && x <= lim && y >= 1 && y <= lim)
	{
		swap(x, y);
		return fractal(div, x,y);
	}
	if (x > lim && x <= 2* lim && y >= 1 && y <= lim)
	{

		x = x % lim;
		if (x == 0)
			x = lim;
		return (div) + fractal(div, x,y);

	}
	if (x > lim && x <= 2* lim && y > lim && y <= 2* lim)
	{
		x = x % lim;
		if (x == 0)
			x = lim;
		y = y % lim;
		if (y == 0)
			y = lim;

		return 2*div + fractal(div, x,y);

	}

	if (x >= 1 && x <= lim && y > lim && y <= 2* lim)
	{
		y = y % lim;
		if (y == 0)
			y = lim;
		long long a = lim - y + 1;
		long long b = lim - x + 1;
		x = a;
		y = b;
		return  3*div + fractal(div, x,y);

	}
}

int main()
{
	f >> n >> y >> x;
	dim = (1 << (n << 1));
	g << fractal(dim,x,y) - 1;
	return 0;
}