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(≤100), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the  (x,y) 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  (x,y) 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<queue>
  3. #include<stack>
  4. #include<cmath>
  5. #include<iostream>
  6. #include<algorithm>
  7. using namespace std;
  8. const int maxn = ;
  9. const int minLen = - 15.0/;
  10.  
  11. struct Point
  12. {
  13. int x,y;
  14. }point[maxn];
  15.  
  16. int path[maxn] = {};
  17. bool vis[maxn] = {};
  18. int n,d;
  19.  
  20. void BFS();
  21. void init(int b[]);
  22. bool cmp(int x,int y);
  23. int FirstJump(int v);
  24. bool isSafe(int v);
  25. bool Jump(int v1,int v2);
  26.  
  27. int main()
  28. {
  29. scanf("%d%d",&n,&d);
  30. for (int i = ; i < n; i++)
  31. {
  32. scanf("%d%d",&point[i].x,&point[i].y);
  33. }
  34.  
  35. if (d >= minLen)
  36. {
  37. printf("1\n");
  38. }
  39. else
  40. {
  41. BFS();
  42. }
  43. return ;
  44. }
  45.  
  46. void BFS()
  47. {
  48. int b[maxn];
  49. init(b);
  50. sort(b,b+n,cmp);
  51.  
  52. queue<int> q;
  53. int last;
  54. int tail;
  55. int step = ;
  56.  
  57. for (int i = ; i < n; i++)
  58. {
  59. if(FirstJump(b[i]))
  60. {
  61. q.push(b[i]);
  62. vis[b[i]] = true;
  63. last = b[i];
  64. }
  65. }
  66.  
  67. while(!q.empty())
  68. {
  69. int now = q.front();
  70. q.pop();
  71.  
  72. if (isSafe(now))
  73. {
  74. int k =;
  75. stack<int> s;
  76. cout << step << endl;
  77.  
  78. while (k < step)
  79. {
  80. s.push(now);
  81. now = path[now];
  82. k++;
  83. }
  84.  
  85. while (!s.empty())
  86. {
  87. now = s.top();
  88. s.pop();
  89. cout << point[now].x << " " << point[now].y << endl;
  90. }
  91. return;
  92. }
  93.  
  94. for (int i = ; i < n; i++)
  95. {
  96. if (!vis[i] && Jump(now,i))
  97. {
  98. q.push(i);
  99. vis[i] = true;
  100. tail = i;
  101. path[i] = now;
  102. }
  103. }
  104.  
  105. if (last == now)
  106. {
  107. last = tail;
  108. step++;
  109. }
  110. }
  111.  
  112. if (q.empty())
  113. {
  114. cout << "" << endl;
  115. }
  116. }
  117.  
  118. void init(int b[])
  119. {
  120. for (int i = ; i < n; i++)
  121. {
  122. b[i] = i;
  123. }
  124. }
  125.  
  126. bool cmp(int x,int y)
  127. {
  128. return FirstJump(x) < FirstJump(y);
  129. }
  130.  
  131. int FirstJump(int v)
  132. {
  133. int dis = pow(point[v].x,) + pow(point[v].y,);
  134. int dis_Jump = pow(15.0/ + d,);
  135. if (dis <= dis_Jump)
  136. {
  137. return dis;
  138. }
  139. else
  140. {
  141. return ;
  142. }
  143. }
  144.  
  145. bool isSafe(int v)
  146. {
  147. int dis_safe = - d;
  148. return abs(point[v].x) >= dis_safe || abs(point[v].y) >= dis_safe;
  149. }
  150.  
  151. bool Jump(int v1,int v2)
  152. {
  153. int dis_x = pow(point[v1].x-point[v2].x, );
  154. int dis_y = pow(point[v1].y-point[v2].y, );
  155. if (dis_x + dis_y <= d*d)
  156. {
  157. return true;
  158. }
  159. else
  160. {
  161. return false;
  162. }
  163. }

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. pat06-图4. Saving James Bond - Hard Version (30)

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

  3. 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 ...

  4. 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. 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 ...

  6. Saving James Bond - Easy Version (MOOC)

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

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

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

  8. Saving James Bond - Hard Version

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

  9. PAT Saving James Bond - Easy Version

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

随机推荐

  1. java基础 super和this

    /** * super关键字的用法有三种: * 1.在子类的成员方法中,访问父类的成员变量 * 2.在子类的成员方法中,访问父类的成员方法 * 3.在子类的构造方法中,访问父类的构造方法 * * th ...

  2. C# 实用代码段

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  3. 2019 途牛旅游网java面试笔试题 (含面试题解析)

      本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.途牛旅游网等公司offer,岗位是Java后端开发,因为发展原因最终选择去了途牛旅游网,入职一年时间了,也成为 ...

  4. IT之快速提高效率的方法与思考

    前言 文章也没什么很高深的问题,大概花个5分钟能看完.是一些大家都知道的道理,作为提醒与总结. 关于提高方面的内容,一般都有个人的方法,但大致都一致.可分为几个步骤. 框架.工具使用相关 使用框架.工 ...

  5. 【转载】C#中使用Insert方法往ArrayList集合指定索引位置插入新数据

    ArrayList集合是C#中的一个非泛型的集合类,是弱数据类型的集合类,可以使用ArrayList集合变量来存储集合元素信息,在ArrayList集合操作过程中,可以使用ArrayList集合类的I ...

  6. jQuery简易Ajax(六)

    一.jQuery中ajax的两种书写方式[一般采用第二种方式]1.$.ajax(url,[setting]); 2.$.ajax([setting]); setting参数说明:setting为一个对 ...

  7. 41、css总结

      1.阴影:box-shadow:0 5px 20px rgba(0,0,0,.1); 2.css实现滚动进度条效果: body { position: relative; padding: 50p ...

  8. Java语法知识点

    1. 特殊字符 a) \n   换行符 b)  \t   制表符 <--------------------------------------------------------------- ...

  9. Python使用Thrift

    2019年07月30日 14:59:29 Shower稻草人 阅读数 25更多 分类专栏: Python   版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接 ...

  10. pandas的行列显示不全的解决方法

    pd.set_option('display.max_rows', 100) # 显示的最大行数(避免只显示部分行数据) pd.set_option('display.max_columns', 10 ...