• 欢迎访问废江网站,承蒙遇见 QQ群
  • 本站将致力于推送优质的java知识以及算法,开源代码!

06-图2 Saving James Bond – Easy Version

浙大mooc 站点默认 4年前 (2019-11-28) 1103次浏览 已收录 0个评论 扫描二维码

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 whether or not he can escape.

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, print in a line “Yes” if James can escape, or “No” if not.

Sample Input 1:
14 20
25 -15
-25 28
8 49
29 15
-35 -2
5 28
27 -29
-8 -28
-20 -35
-25 -20
-13 29
-30 15
-35 40
12 12
Sample Output 1:
Yes
Sample Input 2:
4 13
-12 12
12 12
-12 -12
12 -12
Sample Output 2:
No

不知道大家有没有和我一样的感觉,好像知道怎么写,却又无从下手,我也是在这题耗了一个多小时感觉还是无从下手,题意我就不说了,不会英文的小朋友百度翻译一下,一看就能看懂了。我的思路是:给了我n只鳄鱼的位置,这些鳄鱼就如图中的点,遍历图的点需要一个起点,起点就是007从岛上可以跳过去的鳄鱼,所以先找出所有的起点,再从这些起点开始遍历,当我们发现,007可以跳到岸上的时候就结束遍历,输出yes,好像逻辑一整,也不是很难,也许是我代码写的少,或者是图学的还不够熟练把,我就是写不出来。所以,我决定把教材上的练习过一遍,图的遍历的应用,也正好给图的遍历那篇博客的图的遍历的应用板块补全,回来我在写这一题,看看是不是豁然开朗。虽然,我不是很厉害的大佬,也不是一个好的博客写主,没有好的文采,但是,我会给你们看我解决问题的一点一滴的过程。(⊙﹏⊙)希望能帮到你们,一起努力

看了一个小时的图应用,回来做了这道题,思路是给所有鳄鱼放在一个数组里面,先从岸上007能够跳到的鳄鱼开始遍历,代码基本都写了注释,但是提交的时候有三个错误,我也很无奈,找了半天不知道哪错了


废江博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:06-图2 Saving James Bond – Easy Version
喜欢 (0)
[]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址