题目:http://pta.patest.cn/pta/test/16/exam/4/question/672

PTA - Data Structures and Algorithms (English) - 5-10

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
 

解法转自:http://blog.csdn.net/u013167299/article/details/42267129

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
//#define lson rt<<1,l,MID
//#define rson rt<<1|1,MID+1,r
//#define lson root<<1
//#define rson root<<1|1
//#define MID ((l+r)>>1)
typedef long long ll;
typedef pair<int,int> P;
const int maxn=105;
const int base=1000;
const int inf=999999;
const double eps=1e-5;struct node
{double x,y;   //坐标的X,Yint num;      //坐标的标号 便于标记(就像map的key)
} p[maxn];        //自定义图的节点 存储图bool vis[maxn];   //访问标记
double d,n;       //鳄鱼数量,可跳跃的最大距离int first_dis=1;      //第一次是在中心半径为15的岛上,所以特殊处理
//中心岛/鳄鱼->鳄鱼的距离
double dis(double x,double y,double xx,double yy)
{if(first_dis){return d+15-sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));first_dis=0;}else return d-sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));
}int first_pan=1;      //第一次是在中心半径为15的岛上,所以特殊处理
//判断是否可以到岸上
bool pan(node s)
{if(fisrt_pan){first_pan=0;if(fabs(s.x-50)<=d+15 || fabs(s.x+50)<=d+15 || fabs(s.y-50)<=d+15 || (s.y+50)<=d+15)return true;}else if(fabs(s.x-50)<=d || fabs(s.x+50)<=d || fabs(s.y-50)<=d || (s.y+50)<=d)return true;return false;
}//深度优先
int dfs(node s)
{if(pan(s)){return 1;}if(!vis[s.num]){vis[s.num]=true;for(int i=1; i<=n; i++){if(!vis[p[i].num] && dis(p[i].x,p[i].y,s.x,s.y)>=0){if(dfs(p[i])==1)return 1;}}}return 0;
}int main()
{cin >> n >> d;for(int i=1; i<=n; i++){cin >> p[i].x >> p[i].y;p[i].num=i;}node s;s.x=s.y=s.num=0;  //初始位置(0,0),num标记为0if(dfs(s))puts("Yes");elseputs("No");return 0;
}

转载于:https://www.cnblogs.com/claremore/p/4849695.html

PTA 5-10 Saving James Bond-Easy (25) - 图 - DFS相关推荐

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

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

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

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

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

  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. 算法 图2 Saving James Bond - Easy Version

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

  8. Saving James Bond(c++)

    Saving James Bond(c++) 题目描述: This time let us consider the situation in the movie "Live and Let ...

  9. 图和两种遍历,Saving James Bond

    图可以作为表示指定环境内所有对象的关系的形式.树可以认为是图的子集,图中节点的联系可能是成环的. 图的元素包括边和点,按照不同的需要可能侧重表达点之间的关系或者点本身的信息. int graph[10 ...

最新文章

  1. 计算机网络技术包括哪几种,计算机网络技术包含的两个主要技术是计算机技术和( )。...
  2. [Angular 2] @ngrx/devtools demo
  3. hadoop python入门_MRJob 极速入门,Python玩转Hadoop你会么?
  4. Java 查找指定类型的数组元素
  5. 攻略:如何快速赚取积分,Get云栖大会资料
  6. oracle rac alter日志,ORACLE 11G RAC 增加日志组及增大日志文件
  7. log4j2 mysql_spring boot使用log4j2将日志写入mysql数据库
  8. C#LeetCode刷题之#622-设计循环队列​​​​​​​(Design Circular Queue)
  9. python输入成绩求总分和平均分_python脚本如何输入成绩求平均分?
  10. 站群服务器和虚拟主机的区别,WordPress虚拟主机与站群服务器之间有什么关系 - WordPress 多站点站群...
  11. 【Linux】预编译,编译,汇编,链接的四过程
  12. python学习_Python学习资料整理
  13. Tomcat乱码情况完美解决
  14. oracle solaris 10 系统 下载,更新 Oracle Solaris 11 系统中的软件
  15. linux伊甸园,新手学堂:给Ubuntu系统配置Java开发环境-Linux伊甸园----Linux|Unix|新闻|下载|论坛|人才|教程|自由软件|...
  16. axure能做剪切蒙版吗_***自动售货机能做吗
  17. 在kaggle的论坛上上传图片
  18. Thor UI - 轻量简洁的免费开源移动端 UI 组件库,支持原生小程序和 uni-app
  19. oracle 输出全角空格,mac系统中如何切换全角半角?苹果电脑输入法全角半角切换快捷键介绍...
  20. Simulink学习之Combinatorial Logic模块

热门文章

  1. 总结新浪friendship接口
  2. 华为的创新——流程和组织结构
  3. html——windows.onload()与$(document).ready()区别
  4. ArcGIS水文分析实战教程(18) 河段桩号与线性参考
  5. 使用yaml文件创建deployment来部署一个应用程序到k8s集群
  6. 认识HTML5的WebSocket 1
  7. javaweb编辑器ckeditor配置_ckeditor编辑器在java项目中配置
  8. python怎样播放音乐_Python如何播放音乐?
  9. html dom子节点,HTML DOM 节点
  10. Navicat加载缓慢