Cod sursă (job #513436)

Utilizator avatar vcernea Cernea Victor vcernea IP ascuns
Problemă Romb2 (clasele 9-10) Compilator cpp | 2,01 kb
Rundă Arhiva de probleme Status evaluat
Dată 16 dec. 2019 21:34:15 Scor 100
#include <iostream>
#include <fstream>

using namespace std;

bool panta(double x, double y, double dx, double dy) {
	if ((y / x) > (dy / dx)) {
		return 1;
	}
	return 0;
}

long long int solutie(int ord,
	double x,
	double y,
	double dx,
	double dy,
	long long zona) {
	if (ord == 0) {
		return zona;
	}
	if (x >= 0) {
		if (y >= 0) {                              // NE
			if (panta(x, y, dx / 2, dy / 2) == 1) {  // zona I
				return solutie(ord - 1, x, y - (dy / 2), dx / 2, dy / 2,
											 (1LL * 4 * zona) - 3);
			} else {  // zona IV
				return solutie(ord - 1, x - (dx / 2), y, dx / 2, dy / 2,
											 (1LL * 4 * zona));
			}
		} else {                                    // SE
			if (panta(x, y, dx / 2, -dy / 2) == 1) {  // zona IV
				return solutie(ord - 1, x - (dx / 2), y, dx / 2, dy / 2,
											 (1LL * 4 * zona));
			} else {  // zona III
				return solutie(ord - 1, x, y + (dy / 2), dx / 2, dy / 2,
											 (1LL * 4 * zona) - 1);
			}
		}
	} else {
		if (y >= 0) {                               // NV
			if (panta(x, y, -dx / 2, dy / 2) == 0) {  // zona I
				return solutie(ord - 1, x, y - (dy / 2), dx / 2, dy / 2,
											 (1LL * 4 * zona) - 3);
			} else {  // zona II
				return solutie(ord - 1, x + (dx / 2), y, dx / 2, dy / 2,
											 (1LL * 4 * zona) - 2);
			}
		} else {                                     // SV
			if (panta(x, y, -dx / 2, -dy / 2) == 0) {  // zona II
				return solutie(ord - 1, x + (dx / 2), y, dx / 2, dy / 2,
											 (1LL * 4 * zona) - 2);
			} else {  // zona III
				return solutie(ord - 1, x, y + (dy / 2), dx / 2, dy / 2,
											 (1LL * 4 * zona) - 1);
			}
		}
	}
}

int main() {
	ifstream file_in("romb2.in");
	ofstream file_out("romb2.out");

	int t;
	int dx, dy, ord, x, y;

	// Citirea datelor
	file_in >> t;

	// Calcularea solutiei
	for (; t > 0; t--) {
		file_in >> dx >> dy >> ord >> x >> y;
		// Afisarea solutiei
		file_out << solutie(ord, x, y, dx, dy, 1LL) << "\n";
	}

	return 0;
}