题目来源:http://pta.patest.cn/pta/test/18/exam/4/question/625

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
/*
能够跳上的鳄鱼相当于相邻的点,第一步比较特殊单独处理
每次DFS代表一种拯救方案,只要存在一种方案即可获救
*/
#include <cstdio>
#include <cmath>
#include <cstdlib>const double ISLAND_RADIUS = 15.0 / 2;      //孤岛半径
const double SQUARE_SIZE = 100.0;           //湖(正方形)的大小
const int N = 110;                          //鳄鱼(点)的最大数

typedef struct Point
{double x, y;
} Position;Position P[N];
bool Visited[N];
int n;
double d;void Save007();
bool DFS(int V);
bool FirstJump(int V);
bool Jump(int V1, int V2);
bool IsSave(int V);int main()
{scanf("%d%lf", &n, &d);for (int i = 0; i < n; i++)scanf("%lf%lf", &(P[i].x), &(P[i].y));for (int i = 0; i < n; i++)Visited[i] = false;Save007();return 0;
}void Save007()
{bool IsSave = false;for (int i = 0; i < n; i++){if (!Visited[i] && FirstJump(i)){IsSave = DFS(i);if (IsSave)break;}}if (IsSave)printf("Yes\n");elseprintf("No\n");
}bool DFS(int V)
{Visited[V] = true;bool answer = false;if (IsSave(V))return true;for (int i = 0; i < n; i++){if (!Visited[i] && Jump(V, i))answer = DFS(i);if (answer)break;}return answer;
}bool IsSave(int V)
{return (abs(P[V].x) >= 50 - d)|| (abs(P[V].y) >= 50 - d);
}bool FirstJump(int V)
{return sqrt(P[V].x * P[V].x + P[V].y * P[V].y)<= d + ISLAND_RADIUS;
}bool Jump(int V1, int V2)
{return sqrt((P[V1].x - P[V2].x) * (P[V1].x - P[V2].x) +(P[V1].y - P[V2].y) * (P[V1].y - P[V2].y))<= d;
}

转载于:https://www.cnblogs.com/llhthinker/p/4844990.html

06-图2 Saving James Bond - Easy Version相关推荐

  1. 六、图(上):Saving James Bond - Easy Version

    目录 题目描述 代码 注意事项 题目描述 This time let us consider the situation in the movie "Live and Let Die&quo ...

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

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

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

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

  5. Saving James Bond - Easy Version

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

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

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

  7. 图5 Saving James Bond - Hard Version

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

  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. vue单向数据流与双向绑定两者区别
  2. ORA-00031: session marked for kill 标记要终止的会话
  3. 魔方机器人需要特制魔方吗_火影忍者手游:如果新春水门金币团购,你会夸魔方良心吗?...
  4. 小狗拉菲扫地机器人_小狗电器:2018年最值得入手的五款扫地机器人
  5. 27.Linux/Unix 系统编程手册(上) -- 程序的执行
  6. 【leetcode_easy】590. N-ary Tree Postorder Traversal
  7. jvm系列(五):tomcat性能调优和性能监控(visualvm)
  8. 012-JDK可视化监控工具-jstack
  9. 枚举 函数 c语言,在C语言中函数中使用枚举类型和结构
  10. 腾讯云服务器挂载云硬盘
  11. 趣写算法之匈牙利算法
  12. 2022-2028年全球与中国老年手机行业发展趋势及竞争策略研究
  13. NTC热敏电阻与浪涌电流,热启动不会失效?
  14. 1.dom4j 解析xml
  15. Docker删除镜像/容器
  16. Day01-Dos命令
  17. 为什么勒索软件攻击激增?
  18. 物联卡中心:物联卡被当作流量卡出售违法吗?看完你就知道了!
  19. MAC 版QQ如何多开
  20. 消防给水和消火栓系统(一)

热门文章

  1. oracle connection 有时能取到有时候又取不到
  2. 三篇论文之bigtable
  3. 市值蒸发4460亿美元、股价下跌10%,苹果泡沫终于来了!
  4. 干货|靶场|工具|字典 分享
  5. numpy 的基本使用1
  6. 砍掉九成代码,重构并简化YOLOv5图像目标检测推理实现
  7. Mahout快速入门教程
  8. 从工作实践中积累Linux常用脚本(一)
  9. 深入理解Spark 2.1 Core (一):RDD的原理与源码分析
  10. submit与execute区别