题目地址

https://pta.patest.cn/pta/test/16/exam/4/question/672

5-10 Saving James Bond - Easy Version   (25分)

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 NN (\le 100≤100), the number of crocodiles, and DD, the maximum distance that James could jump. Then NN lines follow, each containing the (x, y)(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

比较简单的一个题,找所有可以起跳的点设为start,可以上岸的点设为finish然后把在跳跃距离内的点连起来遍历所有start,如果路径上遇到finish,那么是可以上岸的
/*
评测结果
时间  结果  得分  题目  编译器 用时(ms)    内存(MB)    用户
2017-07-02 00:53    答案正确    25  5-10    gcc 2   1
测试点结果
测试点 结果  得分/满分   用时(ms)    内存(MB)
测试点1    答案正确    7/7 2   1
测试点2    答案正确    6/6 1   1
测试点3    答案正确    3/3 2   1
测试点4    答案正确    3/3 2   1
测试点5    答案正确    3/3 1   1
测试点6    答案正确    3/3 1   1
*/
#include<stdio.h>
#include<math.h>
#define MAX_CROCODILE 100
#define CENTRAL_ISLAND_R 7.5
#define BORDER 50
#define TRUE 1
#define FALSE 0struct tCrocoVertex
{int x;int y;int start;int finish;
} gNodeTab[MAX_CROCODILE];int gMatrix[MAX_CROCODILE][MAX_CROCODILE];
int gVisitedFlag[MAX_CROCODILE];
int gCanBeSavedFlag=FALSE;void FindStartAndFinishNode(int N,int jumpDistance)
{int i,distSquare;float startDistSquare=(jumpDistance+CENTRAL_ISLAND_R)*(jumpDistance+CENTRAL_ISLAND_R);for(i=0;i<N;i++){distSquare=(gNodeTab[i].x)*(gNodeTab[i].x)+(gNodeTab[i].y)*(gNodeTab[i].y);if(distSquare<=startDistSquare){gNodeTab[i].start=TRUE;}gNodeTab[i].finish=    (abs(gNodeTab[i].x-BORDER)<=jumpDistance ||abs(gNodeTab[i].x+BORDER)<=jumpDistance ||abs(gNodeTab[i].y-BORDER)<=jumpDistance ||abs(gNodeTab[i].y+BORDER)<=jumpDistance)?TRUE:FALSE;}
}void BuildMatrix(int N,int jumpDistance)
{int i,j;int distSquare,jumpDistanceSquare;jumpDistanceSquare=jumpDistance*jumpDistance;for(i=0;i<N;i++)for(j=0;j<i;j++){distSquare=  (gNodeTab[i].x-gNodeTab[j].x)*(gNodeTab[i].x-gNodeTab[j].x)+(gNodeTab[i].y-gNodeTab[j].y)*(gNodeTab[i].y-gNodeTab[j].y);if(distSquare<=jumpDistanceSquare){gMatrix[i][j]=TRUE;gMatrix[j][i]=TRUE;}}
}void DFS(int x,int N)
{if(gCanBeSavedFlag==TRUE)return;int i;if(gNodeTab[x].finish==TRUE)gCanBeSavedFlag=TRUE;gVisitedFlag[x]=TRUE;for(i=0;i<N;i++){if(gMatrix[x][i]==TRUE && gVisitedFlag[i]==FALSE)DFS(i,N);}
}
void DBG_ShowStatus(N)
{int i,j;for(i=0;i<N;i++){printf("ID:%d,x:%d,y:%d,start:%d,finish:%d,visited:%d\n",i,gNodeTab[i].x,gNodeTab[i].y,gNodeTab[i].start,gNodeTab[i].finish,gVisitedFlag[i]);}for(i=0;i<N;i++){for(j=0;j<N;j++)printf("%d ",gMatrix[i][j]);printf("\n");}}
int main()
{int i,N,D;scanf("%d %d",&N,&D);for(i=0;i<N;i++){scanf("%d %d",&gNodeTab[i].x,&gNodeTab[i].y);}FindStartAndFinishNode(N,D);BuildMatrix(N,D);for(i=0;i<N;i++){if(gCanBeSavedFlag==TRUE)break;if(gNodeTab[i].start==TRUE && gVisitedFlag[i]==FALSE)DFS(i,N);}if(gCanBeSavedFlag==TRUE)printf("Yes");elseprintf("No");
//  DBG_ShowStatus(N);
}

  

转载于:https://www.cnblogs.com/gk2017/p/7141016.html

PTA 06-图2 Saving James Bond - Easy Version (25分)相关推荐

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

  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. LeetCode Wiggle Sort II
  2. 企业级rancher搭建Kubernetes(采用rancher管理平台搭建k8s)
  3. 单点登陆的三种实现方式
  4. 7-2 城市间紧急救援 (25 分)
  5. 4am永远 鼠标按键设置_4AM称霸PCL和PEL 绝地求生与和平精英的双端冠军 | 电玩巴士...
  6. 通达信手机版分时图指标大全_今天教大家怎么把通达信副图指标源码导入手机通达信软件上。...
  7. 亿图图示+linux版本,亿图图示linux版下载
  8. 如何快速去除PDF的密码和限制:遇到PDF被加密,不能复制、编辑,怎么办?教大家一个又快又好用的方法、实用。
  9. 逗娱-游戏程序开发实习生测试题
  10. ADB 自动补全 及 offline 解决方法
  11. JavaScript 专题之惰性函数
  12. OA选型 三条底线不能碰
  13. 改变命运的早上三分钟 之 一
  14. 主流平面设计软件推荐,实用工具推荐必坑指南!
  15. python编写一个程序、判断用户输入的数是正数还是负数_python判断正负数方式
  16. linux查看是否已安装GCC及安装GCC
  17. git 提交时报错:Branch ‘master‘ set up to track remote branch ‘master‘ from ‘origin‘.
  18. 给aws的root账户新建密码
  19. 在线交易系统 服务器1,金字塔决策交易系统金钻版服务器及客户端安装配置说明1.doc...
  20. html5表单下拉列表样式,表单的各种下拉和样式大全

热门文章

  1. 计算指数c语言2的n次方,计算2的N次方........有什么错吗?
  2. jquery多维对象计算个数_多维尺度分析理论概述
  3. 穿越剧_张宇鑫:穿越剧——从皇帝到乞丐
  4. python初学篇笔记_Python学习笔记(基础篇)
  5. 大话“用户注册激活,忘记密码”发送邮件功能
  6. js动态增加行 删除行
  7. Solr操作中新手常见问题
  8. 想做硬件开发的人员必看
  9. python二叉树的创建与遍历
  10. arduino 入门套件_计算机视觉入门套件