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 by 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 a shortest path to reach one of the banks. The length of a path is the number of jumps that James has to make.

Input Specification:

Each input file contains one test case. Each case starts with a line containing two positive integers N (≤), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the ( location of a crocodile. Note that no two crocodiles are staying at the same position.

Output Specification:

For each test case, if James can escape, output in one line the minimum number of jumps he must make. Then starting from the next line, output the position ( of each crocodile on the path, each pair in one line, from the island to the bank. If it is impossible for James to escape that way, simply give him 0 as the number of jumps. If there are many shortest paths, just output the one with the minimum first jump, which is guaranteed to be unique.

Sample Input 1:

  1. 17 15
  2. 10 -21
  3. 10 21
  4. -40 10
  5. 30 -50
  6. 20 40
  7. 35 10
  8. 0 -10
  9. -25 22
  10. 40 -40
  11. -30 30
  12. -10 22
  13. 0 11
  14. 25 21
  15. 25 10
  16. 10 10
  17. 10 35
  18. -30 10

Sample Output 1:

  1. 4
  2. 0 11
  3. 10 21
  4. 10 35

Sample Input 2:

  1. 4 13
  2. -12 12
  3. 12 12
  4. -12 -12
  5. 12 -12

Sample Output 2:

  1. 0
  1. #include<cstdio>
  2. #include<iostream>
  3. #include<stack>
  4. #include<queue>
  5. #include<cmath>
  6. #include<algorithm>
  7. using namespace std;
  8. const int maxn = ;
  9. const int minLen = - /;
  10. struct Pointer{
  11. int x,y;
  12. }point[maxn];
  13. int path[maxn] = {-};
  14. bool visited[maxn] = {false};
  15. int d[maxn],n,m;
  16.  
  17. void init(){
  18. for(int i = ; i < n; i++) d[i] = i;
  19. }
  20.  
  21. bool Jump(int u,int v){
  22. int d1 = pow(point[u].x - point[v].x,);
  23. int d2 = pow(point[u].y - point[v].y,);
  24. int r = m * m;
  25. if(r >= d1 + d2) return true;
  26. else return false;
  27. }
  28.  
  29. int firstJump(int v){
  30. int d1 = pow(point[v].x,);
  31. int d2 = pow(point[v].y,);
  32. int r = (m+7.5)*(m+7.5);
  33. if(r >= d1 + d2) return d1+d2;
  34. else return ;
  35. }
  36.  
  37. bool isSafe(int x) { /* 判断从当前点能否跳到岸上 */
  38. if ((point[x].x - m <= -) || (point[x].x + m >= ) || (point[x].y - m <= -) || (point[x].y + m >= ))
  39. return true;
  40. return false;
  41. }
  42.  
  43. bool cmp(int x,int y){
  44. return firstJump(d[x]) < firstJump(d[y]);
  45. }
  46.  
  47. void BFS() { /* 用bfs来判断最少要踩几个小鳄鱼才能上岸 */
  48. int b[];
  49. queue<int>q;
  50. /* 将第一步能踩到的鳄鱼按距离从小到大的顺序进队列~ 因为输出结果要保证在踩的鳄鱼数量相等的情况下 输出第一步距离最短的~~*/
  51. for (int i = ; i < n; i++) {
  52. b[i] = i;
  53. }
  54. sort(b, b + n, cmp); /* 按照第一步的距离排序~~~ */
  55. int last;
  56. for (int i = ; i < n; i++) {
  57. if (firstJump(b[i])) { /* 能跳上去! */
  58. q.push(b[i]);
  59. visited[b[i]] = true; /* 指向当前层数最后一个数~ */
  60. last = b[i];
  61. }
  62. }
  63. int step = ; /* 记录最少要跳跃的次数 */
  64. int tail;
  65. while (!q.empty()) {
  66. int p = q.front();
  67. q.pop();
  68. if (isSafe(p)) {
  69. int k = ;
  70. stack<int> s;
  71. cout << step << endl;
  72. while (k < step) {
  73. //cout << point[p].x << " " << point[p].y << endl;
  74. s.push(p);
  75. p = path[p];
  76. k++;
  77. }
  78. while (!s.empty()) {
  79. p = s.top();
  80. s.pop();
  81. cout << point[p].x << " " << point[p].y << endl;
  82. }
  83. return;
  84. }
  85. for (int i = ; i < n; i++) {
  86. if (!visited[i] && Jump(p, i)) { /* 没踩过并且能跳到 */
  87. q.push(i);
  88. path[i] = p; /* 记得当前进队节点的父节点~ */
  89. visited[i] = true;
  90. tail = i; /* 指向下一层的最后一个元素 */
  91. }
  92. }
  93. if (last == p) { /* 即将进入下一层~ */
  94. step += ;
  95. last = tail;
  96. }
  97. }
  98. if (q.empty()) { /* 如果队列为空 说明没跳出去啊~ */
  99. cout << "" << endl;
  100. }
  101. }
  102.  
  103. int main(){
  104. scanf("%d%d",&n,&m);
  105. init();
  106. for(int i = ; i < n; i++){
  107. scanf("%d%d",&point[i].x,&point[i].y);
  108. }
  109. if(m >= minLen){
  110. printf("1\n");
  111. return ;
  112. }
  113. BFS();
  114. return ;
  115. }

07-图5 Saving James Bond - Hard Version (30 分)的更多相关文章

  1. PTA 07-图5 Saving James Bond - Hard Version (30分)

    07-图5 Saving James Bond - Hard Version   (30分) This time let us consider the situation in the movie ...

  2. 07-图5 Saving James Bond - Hard Version (30 分)

    This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...

  3. pat06-图4. Saving James Bond - Hard Version (30)

    06-图4. Saving James Bond - Hard Version (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...

  4. PTA 06-图2 Saving James Bond - Easy Version (25分)

    This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...

  5. 06-图2 Saving James Bond - Easy Version (25 分)

    This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...

  6. Saving James Bond - Easy Version 原创 2017年11月23日 13:07:33

    06-图2 Saving James Bond - Easy Version(25 分) This time let us consider the situation in the movie &q ...

  7. Saving James Bond - Easy Version (MOOC)

    06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...

  8. pat05-图2. Saving James Bond - Easy Version (25)

    05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...

  9. Saving James Bond - Hard Version

    07-图5 Saving James Bond - Hard Version(30 分) This time let us consider the situation in the movie &q ...

  10. PAT Saving James Bond - Easy Version

    Saving James Bond - Easy Version This time let us consider the situation in the movie "Live and ...

随机推荐

  1. day17-jdbc 5.url介绍

    url用于标识数据库的位置,用于标识找哪个数据库. 总结:url是路径,其实就是确定是哪个数据库.用来确定我用的是哪一个数据库,并且通知我这个Connection或者是这个DriverManager获 ...

  2. 洛谷P2146 树链剖分

    题意 思路:直接树链剖分,用线段树维护即可,算是树剖的经典题目吧. 代码: #include <bits/stdc++.h> #define ls(x) (x << 1) #d ...

  3. 文本框控件JTextField和JTextArea的使用

    -----------------siwuxie095                             工程名:TestUI 包名:com.siwuxie095.ui 类名:TestTextF ...

  4. final 子类禁止重写

    <?php //子类中编写和父类中完全一样的函数,是对父类中的函数进行重写 class BaseClass{ public function test() { echo "BaseCl ...

  5. 分布式锁2 Java非常用技术方案探讨之ZooKeeper 【转载】

    前言:       由于在平时的工作中,线上服务器是分布式多台部署的,经常会面临解决分布式场景下数据一致性的问题,那么就要利用分布式锁来解决这些问题.以自己结合实际工作中的一些经验和网上看到的一些资料 ...

  6. OpenCV Mat数据类型指针ptr的使用

    OpenCV Mat数据类型指针ptr的使用 cv::Mat image = cv::Mat(400, 600, CV_8UC1); //宽400,长600 uchar * data00 = imag ...

  7. ZROI2018提高day1t2

    传送门 分析 考场上看错了第一个条件,于是觉得是个简单贪心,随便取了每一个点的最大收益然后算了一下,就得了40pts...看来读对题很重要呀qwq.实际的正解是这样的:我们将每一个i与f[i]连一条边 ...

  8. Luogu 3586 [POI2015]LOG

    考虑离散化后开权值线段树. 设序列中不小于$s$的数有$cnt$个,小于$s$的数的和为$sum$. 那么操作Z能成功的充要条件是$sum \geq (c - cnt) * s$. 如果序列中不小于$ ...

  9. 动态tab页

    1.前台代码 <%-- builed by manage.aspx.cmt  [ver:2015.25.26] at 2015-06-26 15:25:42 --%> <%@ Pag ...

  10. spring第三篇

    在昨天下午更新sprin第二篇中,叙述了将对象交给spring创建和管理,今天在spring第三篇中,主要写两个点一是spring的思想 二是spring中bean元素的属性配置. 1 spring思 ...