题目链接:>_>
Saving James Bond
This time let us consider the situation in the movie “Live and Let Die” in which James Bond, the world’s most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land at the center of a lake filled with crocodiles. There he performed the most daring action to escape – he jumped onto the head of the nearest crocodile! Before the animal realized what was happening, James jumped again onto the next big head… Finally he reached the bank before the last crocodile could bite him (actually the stunt man was caught by the big mouth and barely escaped with his extra thick boot).
Assume that the lake is a 100×100 square one. Assume that the center of the lake is at (0,0) and the northeast corner at (50,50). The central island is a disk centered at (0,0) with the diameter of 15. A number of crocodiles are in the lake at various positions. Given the coordinates of each crocodile and the distance that James could jump, you must tell him whether he could escape.If he could,tell him the shortest length he has to jump and the min-steps he has to jump for shortest length.
Input
The input consists of several test cases. Each case starts with a line containing n <= 100, the number of crocodiles, and d > 0, the distance that James could jump. Then one line follows for each crocodile, containing the (x, y) location of the crocodile. Note that x and y are both integers, and no two crocodiles are staying at the same position.
Output
For each test case, if James can escape, output in one line the shortest length he has to jump and the min-steps he has to jump for shortest length. If it is impossible for James to escape that way, simply ouput “can’t be saved”.
Sample Input
4 10
17 0
27 0
37 0
45 0
1 10
20 30
Sample Output
42.50 5
can’t be saved
题目大意:
在为左下角(-50,-50),右上角(50,50)的100*100图中,中心岛的坐标为(0,0),中心岛的直径为15,给出每一次跳的最远距离和可以踩的点的坐标,问路程和步数,不成立输出"can’t be saved"。
思路:
将起点和终点分别看成一个点,看从起点可以跳到哪些点,和哪些点可以跳到终点,将他们存进图中,再跑一遍floyd即可。
注意:
中心岛的直径为15,半径为7.5
精度
坐标在岛上的点不用考虑,超过地图的点也不用考虑
代码:
#include<bits/stdc++.h>
using namespace std;
#define inf 999999
struct node {
double x, y;
}a[105];
double mp[105][105];
int v[105][105];
const double eps = 1e-12;
void init(int n) {
int i, j;
memset(v, 0, sizeof(v));
for (i = 0; i <= n + 1; i++) {
for (j = 0; j <= n + 1; j++) {
mp[i][j] = inf;
}
}
}
double panduan(int x1, int y1, int x2, int y2, double d) {
double ans = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
if (ans > d + eps)return -1;
else return ans;
}
int main() {
int n;
double d;
while (~scanf("%d %lf", &n, &d)) {
init(n);
int i, j;
int m = 1;
double q1, q2;
for (i = 1; i <= n; i++) {
scanf("%lf %lf", &q1, &q2);
if (fabs(q1) < 8 && fabs(q2) < 8 || fabs(q1) > 50 && fabs(q2) > 50)continue;
else {
a[m].x = q1;
a[m].y = q2;
m++;
}
}
if (d >= 42.5 + eps) {
printf("42.5 1\n");
continue;
}
n = m - 1;
if (n == 0) {
printf("can't be saved\n");
continue;
}
for (i = 1; i <= n; i++) {
double ans = sqrt(a[i].x * a[i].x + a[i].y * a[i].y);
if (ans - 7.5 - d <= eps) {
mp[0][i] = mp[i][0] = ans - 7.5;
v[0][i] = v[i][0] = 1;
}
}
for (i = 1; i <= n; i++) {
double ans2 = min(abs(50 - fabs(a[i].x)), abs(50 - fabs(a[i].y)));
if (ans2 - d <= eps) {
mp[i][n + 1] = mp[n + 1][i] = ans2;
v[i][n + 1] = v[n + 1][i] = 1;
}
}
for (i = 1; i <= n; i++) {
for (j = i; j <= n; j++) {
double ans = panduan(a[i].x, a[i].y, a[j].x, a[j].y, d);
if (ans != -1) {
mp[i][j] = mp[j][i] = ans;
v[i][j] = v[j][i] = 1;
}
}
}
for (int k = 0; k <= n + 1; k++) {
for (i = 0; i <= n + 1; i++) {
for (j = 0; j <= n + 1; j++) {
if (mp[i][j] - (mp[i][k] + mp[k][j]) >= eps) {
mp[i][j] = mp[i][k] + mp[k][j];
v[i][j] = v[i][k] + v[k][j];
}
}
}
}
if (mp[0][n + 1] == inf) printf("can't be saved\n");
else printf("%.2f %d\n", mp[0][n + 1], v[0][n + 1]);
}
return 0;
}