1.题目描述:
Saving James Bond
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3347 Accepted Submission(s): 698
Problem Description
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.
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
Author
weigang Lee
Recommend
有一片100*100的湖泊,中心坐标(0,0),即湖泊右上角的坐标是(50,50),湖泊中间有一片以(0,0)为圆心,15为直径的圆形陆地。现有一个人在陆地,湖泊中散布着一些点可以踩,这个人要利用这些点跳到岸上,求最短路径和最短路径下的最短步数。
3.解题思路:
1 题目讲的是有一个湖100x100这个人刚开始在一个直径为15的圆心在原点的园内,然后要通过跳跃的方式问我们他是否能够到达岸边。如果可以求出最短的路径和步数
2 很明确就是最短路问题。但是这个时候问题来了,起点和终点是在哪里,所以我们采用的是将原点作为起点,岸边做为终点。知道了起点和终点,我们就可以求最短路,但是这个时候会碰到另外一个问题,边的长度。对于这个问题,我们是采取的方法是将这些点分成三类。1类:起点 2类:终点 3类:其它点 ,那么我们就可以分别对这三类的点求出它和其它点的距离。
注意事项:
1 输入的数据中,点的范围可能会在园内或在湖外,所以在输入的时候要判断点是否合法。
2 这一题精度要求很严格,一些比较之类的要注意精度问题
3 注意n = 0 的情况,这里如果n = 0,但是d > 42.5 是可以跳出去的。但是只要有乌龟,这个人就必须通过踩在乌龟上面跳出去,所以n = 0是比较特殊的。
4 n不大所以什么方法都可以做
5 求所需几步的时候利用一个setp[][]数组,首先初始户为0然后将可以到达的点标记为1,最后只要在更新dis[][]的时候更新即可。
4.AC代码:
#include <bits/stdc++.h> #define INF 0x3f3f3f3f #define maxn 100100 #define N 111 #define eps 1e-6 #define pi acos(-1.0) #define e exp(1.0) using namespace std; const int mod = 1e9 + 7; typedef long long ll; typedef unsigned long long ull; struct node { int to, jmp; double val; node() {} node(int a, double b, int c) { to = a; val = b; jmp = c; } friend bool operator< (node a, node b) { if (a.val == b.val) return a.jmp > b.jmp; return a.val > b.val; } }; vector<node> mp[N]; bool vis[N], flag; double x[N], y[N]; double getdis(double x1, double y1, double x2, double y2) { return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2)); } node bfs(int n) { memset(vis, 0, sizeof(vis)); priority_queue<node> q; q.push(node(0, 0.0, 0)); node cur; while (!q.empty()) { cur = q.top(); q.pop(); int u = cur.to; double w = cur.val; int jmp = cur.jmp; if (!vis[u]) { vis[u] = 1; if (u == n + 1) { flag = 1; break; } int sz = mp[u].size(); for (int i = 0; i < sz; i++) { cur.to = mp[u][i].to; if (!vis[cur.to]) { cur.val = w + mp[u][i].val; cur.jmp = jmp + 1; q.push(cur); } } } } return cur; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); long _begin_time = clock(); #endif int n; double d; while (~scanf("%d%lf", &n, &d)) { for (int i = 0; i <= n + 1; i++) mp[i].clear(); for (int i = 1; i <= n; i++) { scanf("%lf%lf", &x[i], &y[i]); double dd = getdis(x[i], y[i], 0.0, 0.0) - 7.5; if (dd <= d) { mp[0].push_back(node(i, dd, 0)); mp[i].push_back(node(0, dd, 0)); } } for (int i = 1; i < n; i++) for (int j = i + 1; j <= n; j++) { double dd = getdis(x[i], y[i], x[j], y[j]); if (dd <= d) { mp[i].push_back(node(j, dd, 0)); mp[j].push_back(node(i, dd, 0)); } } for (int i = 1; i <= n; i++) { double tmp = max(fabs(x[i]), fabs(y[i])); if (50.0 - tmp <= d) { mp[i].push_back(node(n + 1, 50.0 - tmp, 0)); mp[n + 1].push_back(node(i, 50.0 - tmp, 0)); } } flag = 0; node ans = bfs(n); if (flag) printf("%.2f %d\n", ans.val, ans.jmp); else puts("can't be saved"); } #ifndef ONLINE_JUDGE long _end_time = clock(); printf("time = %ld ms.", _end_time - _begin_time); #endif return 0; }