Friday, October 30, 2015

UVa 10947 - Bear with me, again..

// UVa 10947 - Bear with me, again..

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

struct circle {
	int x, y, r;
};

double dist(circle a, circle b) {
	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) - a.r
			- b.r;
}

int main() {
	int k, m;
	while (cin >> k >> m) {
		circle l, fin;
		cin >> l.x >> l.y >> l.r;
		cin >> fin.x >> fin.y >> fin.r;
		int n;
		cin >> n;
		circle c[200];
		for (int i = 0; i < n; i++) {
			cin >> c[i].x >> c[i].y >> c[i].r;
		}
		c[n++] = fin;
		queue<circle> q;
		q.push(l);
		bool taken[200];
		memset(taken, false, sizeof(taken));
		while (!q.empty()) {
			circle f = q.front();
			q.pop();
			for (int i = 0; i < n; i++)
				if (!taken[i] && dist(f, c[i]) <= k * m) {
					taken[i] = true;
					q.push(c[i]);
				}
		}
		if (taken[n - 1])
			cout << "Larry and Ryan will escape!\n";
		else
			cout << "Larry and Ryan will be eaten to death.\n";
	}

	return 0;
}

No comments:

Post a Comment