Rezultati

Up. imeNalogaJezikRezultatČas oddaje
rektifikatorji-2018 Presek C++ 100/100OK 04. okt '18 @ 17:53

Test Točke Porabljen spomin Porabljen čas Status
#1 100/100 3,156 MiB 0,001 s OK

Ocenjevani program (Source.cpp):
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;

	int x1, x2, y1, y2, xk, yk, r;

	for (int i = 0; i < n; ++i) {
		cin >> x1 >> y1 >> x2 >> y2 >> xk >> yk >> r;
		//if (xk < x1 - r || xk > x2 + r || yk < y1 - r || yk > y2 + r) {
		//	cout << "Presek je prazen" << endl;
		//	continue;
		//} else 
		if (xk <= x2 && xk >= x1 && yk <= y2 && yk >= y1) {
			cout << xk << " " << yk << endl;
			continue;
		}
		int r2 = r * r;
		bool found = false;

		for (int i = x1; i <= x2 && !found; ++i) {
			if (r2 >= (xk - i) * (xk - i) + (yk - y1) * (yk - y1)) {
				cout << i << " " << y1 << endl;
				found = true;
			} else if (r2 >= (xk - i) * (xk - i) + (yk - y2) * (yk - y2)) {
				cout << i << " " << y2 << endl;
				found = true;
			}
		}

		for (int i = y1; i <= y2 && !found; ++i) {
			if (r2 >= (xk - x1) * (xk - x1) + (yk - i) * (yk - i)) {
				cout << x1 << " " << i << endl;
				found = true;
			} else if (r2 >= (xk - x2) * (xk - x2) + (yk - i) * (yk - i)) {
				cout << x2 << " " << i << endl;
				found = true;
			}
		}
		if (!found) {
			cout << "Presek je prazen" << endl;
		}
	}

	//system("pause");
	return 0;
}