Wednesday, May 13, 2015

UVa 10357 - Playball !!!

// UVa 10357 - Playball !!!

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;

struct tplayer {
	double x, y, v;
};

struct tball {
	double a, b, c, d, e, f, g;
};

int main() {
	for (int i = 0; i < 8; i++)
		char dummy = getchar();
	int n;
	cin >> n;

	tplayer player[20];
	for (int i = 0; i < n; i++)
		cin >> player[i].x >> player[i].y >> player[i].v;

	string line;
	getline(cin, line);
	for (int i = 0; i < 6; i++)
		char dummy = getchar();
	int m;
	cin >> m;
	for (int j = 1; j <= m; j++) {
		double a, b, c, d, e, f, g;
		cin >> a >> b >> c >> d >> e >> f >> g;
		double D = b * b - 4 * a * c;
		double t1 = -(b + sqrt(D)) / (2 * a);
		double t2 = -(b - sqrt(D)) / (2 * a);
		double t = (t2 <= 0 || 0 < t1 && t1 < t2) ? t1 : t2;
		t = ceil(t);
		double x = d * t + e;
		double y = f * t + g;
		string outcome;
		if (x < 0 || y < 0)
			outcome = "foul";
		else {
			outcome = "safe";
			for (int i = 0; i < n; i++) {
				if (sqrt((x - player[i].x) * (x - player[i].x) + (y - player[i].y) * (y - player[i].y)) / player[i].v <= t) {
					outcome = "caught";
					break;
				}
			}
		}
		printf("Ball %d was %s at (%.0f,%.0f)\n", j, outcome.c_str(), x, y);

	}
	return 0;
}

No comments:

Post a Comment