目录

  • 题目描述
  • 代码
  • 注意事项

题目描述

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

代码

#include<stdio.h>
#include<math.h>
#define MaxNum 100
#define Radius 7.5typedef struct Location Cro;
struct Location{int x;int y;
}CroLoc[MaxNum];int Visited[MaxNum] = {0};
int N,D;int FirstJump(Cro C)
{if ( pow(C.x,2) + pow(C.y,2) <= pow(Radius+D,2) )return 1;elsereturn 0;
}int Jump(Cro C1, Cro C2)
{if( pow(C1.x-C2.x,2) + pow(C1.y-C2.y,2) <= pow(D,2) )return 1;else return 0;
}int IsSafe(i)
{int x = CroLoc[i].x, y = CroLoc[i].y;if( x>=50-D || x<=D-50 || y>=50-D || y<=D-50 )return 1;else return 0;
}int DFS(i)
{int j,answer=0;Visited[i] = 1;if( IsSafe(i) )answer = 1;else{for(j=0;j!=N;++j){if( !Visited[j] && j!=i && Jump(CroLoc[i],CroLoc[j]) )answer = DFS(j);if(answer == 1) break;}}return answer;
}int main()
{scanf("%d %d",&N,&D);int i,answer;for(i=0;i!=N;i++)scanf("\n%d %d",&CroLoc[i].x,&CroLoc[i].y);for(i=0;i!=N;i++){if( !Visited[i] && FirstJump(CroLoc[i]) ){answer = DFS(i);if(answer) break;}}if(answer)printf("Yes");elseprintf("No");return 0;}

注意事项

  1. 因为湖心小岛是有半径的不是一个点,所以第一次跳跃的判断方法和之后的不相同。
  2. 不需要建立图,直接用距离判断是否连通。
  3. 使用全局变量方便。先定义全局变量,然后赋值给全局变量。

六、图(上):Saving James Bond - Easy Version相关推荐

  1. 算法 图2 Saving James Bond - Easy Version

    全部每周作业和视频思考题答案和解析 见 浙江大学 数据结构 思考题+每周练习答案汇总 题目:This time let us consider the situation in the movie & ...

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

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/672 5-10 Saving James Bond - Easy Version   ( ...

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

  4. 图5 Saving James Bond - Hard Version

    全部每周作业和视频思考题答案和解析 见 浙江大学 数据结构 思考题+每周练习答案 题目:This time let us consider the situation in the movie &qu ...

  5. 中国大学MOOC-陈越、何钦铭-数据结构 Saving James Bond - Easy Version

    题目描述: This time let us consider the situation in the movie "Live and Let Die" in which Jam ...

  6. 06-图2 Saving James Bond - Easy Version

    题目来源:http://pta.patest.cn/pta/test/18/exam/4/question/625 This time let us consider the situation in ...

  7. Saving James Bond - Easy Version

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

  8. (c语言)Saving James Bond - Hard Version (30分)

    关于数据结构Mooc后的每一道答案 基本我都已经给出了详解 希望能对大家有所帮助 收藏一下也是方便大家查找吧 希望大家一起进步! (c语言)浙大数据结构Mooc作者答案集 原题题目(谷歌翻译) 全检查 ...

  9. 07-图4. Saving James Bond - Hard Version (30)

    本题测试点5是从小岛范围内可以直接跳到岸边-- 测试点4是验证步数第一跳最小的情况,刚开始没有考虑回溯,所以错了-- #include <stdio.h> #include <str ...

最新文章

  1. 修改系统tabbar的高度
  2. MySQL的安装配置(win7 64-bit)
  3. python对象属性查看
  4. 解决sdk manager无法更新的问题
  5. protobuf简单序列化反序列化示例
  6. Some best freeware
  7. java中函数的表达,如何表达“用T作为参数|的函数字符串,它是TypeScript中T“的键...
  8. Hi3516A开发--USB PCB 设计建议
  9. CDQ分治 Jam's problem again [HDU - 5618]
  10. Spark 资源调度及任务调度
  11. Java Mybatis
  12. count函数_计数函数Count、Counta、Countblank、Countif、Countifs技巧解读
  13. 蓝桥杯 ALGO-25 算法训练 Car的旅行路线
  14. py获取前端的参数_Python小工具系列(3)之参数检查
  15. LightOJ 1410 Consistent Verdicts(找规律)
  16. 已有一个名为“frmadd”的组件。组件的名称必须是唯一的,而且名称必须不区分大小
  17. AI复活明朝历代皇帝,来一场穿越时空的对话!
  18. 一键恢复CGI v3.2.1.0 增强版
  19. linux 查看登录记录,Linux查看用户登陆历史记录
  20. java发微信字体颜色_java微信公众号发送消息模板

热门文章

  1. vscode中flake8报错
  2. 【JVM】调优参数总结
  3. edge或谷歌浏览器打开默认是百度或其他,怎么修改成自己想要的页面
  4. 用Python做兼职接单,简直是爽到离普
  5. Runnable接口和Callable接口的区别
  6. disruptor example
  7. Python:赋值,copy和deepcopy区别
  8. Openstack kvm win7镜像制作(转)
  9. disabled=“true“是什么意思?
  10. windows10无人值守安装