Cod sursa(job #1978779)

Utilizator kriptexPopa Serban kriptex Data 8 mai 2017 19:39:55
Problema Fractal Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <fstream>
#include <math.h>

using namespace std;

double x, y;

double fractal(int k){
	if (!k)
		return 0;
	else
		if (x <= pow(2, k) / 2 && y <= pow(2, k) / 2){ //cadr I
			x = x + y;
			y = x - y;
			x = x - y;
			return fractal(k - 1);
		}
		else
			if (x <= pow(2, k) / 2 && y > pow(2, k) / 2){ //cadr II
				y -= pow(2, k) / 2;
				return (pow(2, k) / 2 * pow(2, k) / 2) + fractal(k - 1);
			}
			else
				if (x > pow(2, k) / 2 && y > pow(2, k) / 2){ //cadr III
					y -= pow(2, k) / 2;
					x -= pow(2, k) / 2;
					return (pow(2, k) / 2 * pow(2, k) / 2) * 2 + fractal(k - 1);
				}
				else
					if (x > pow(2, k) / 2 && y <= pow(2, k) / 2){ //cadr IV
						y = pow(2, k) / 2 - y + 1;
						x = pow(2, k) - x + 1;
						x = x + y;
						y = x - y;
						x = x - y;
						return (pow(2, k) / 2 * pow(2, k) / 2) * 3 + fractal(k - 1);
					}
}

int main(){
	int k;
	ifstream citire ("fractal.in");
	citire >> k >> x >> y;
	citire.close();
	ofstream afisare ("fractal.out");
	afisare << fractal(k);
	afisare.close();
	return 0;
}