Saving James Bond(c++)

题目描述:

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.

输入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

输出1

Yes

输入2

4 13
-12 12
12 12
-12 -12
12 -12

输出2

No

解题代码

// 深搜
#include<bits/stdc++.h>
using namespace std;
int visited[100],n,d;
struct coordinate{      //结构体存放鳄鱼的位置 int x;int y;
}crocodile[105];    //每次是否能跳跃的函数
bool jump(int i,int j)
{return (sqrt(pow(crocodile[i].x-crocodile[j].x,2)+pow(crocodile[i].y-crocodile[j].y,2))<=d);
}//第一次跳跃的函数,因为中间是小岛所以跳跃长度需要加上小岛的直径
bool firstjump(int i)
{return (sqrt(pow(crocodile[i].x,2)+pow(crocodile[i].y,2))<=(d+15));
}bool isarrive(int i)
{int x_length,y_length;x_length=abs(crocodile[i].x)-50;    //看最后一只鳄鱼的位置距离岸的位置 y_length=abs(crocodile[i].y)-50;    //看最后一只鳄鱼的位置距离岸的位置//看看横纵距离是否都小于能跳到的距离,是就说明有答案 if(abs(x_length)<=d || abs(y_length)<=d) return true;else return false;} //深搜
int dfs(int i)
{int ans=0;if(isarrive(i)) //如果上岸了 ,标定 ans=1;else         //没上岸继续搜 {visited[i]=true;for(int j=0;j<n;j++){if(!visited[j]&&jump(i,j))    //搜索条件:还没走过并且跳跃距离之内 {ans=dfs(j);if(ans==1) break; //找到答案就退出寻找 }   }} return ans;
}int main()
{int ans=0;cin>>n>>d;for(int i=0;i<n;i++)cin>>crocodile[i].x>>crocodile[i].y;memset(visited,false,sizeof(visited));  //初始化,让每个位置都是没走过 //遍历所有鳄鱼点,判断,搜索 for(int i=0;i<n;i++){if(!visited[i]&&firstjump(i)){ans=dfs(i);if(ans==1){cout<<"Yes";return 0;} }    }cout<<"No";return 0;
}

Saving James Bond(c++)相关推荐

  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. (模拟+floyd)Saving James Bond

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

  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

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

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

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

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

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

最新文章

  1. struts2的配置
  2. boost::process::system相关的测试程序
  3. 刚到的新公司 前任经理匆匆见了一面 飞鸽传书下载
  4. JWT认证原理、整合springboot实战应用
  5. 加工中心宏程序生成器_宏程序G1铣锥度螺纹NPT
  6. 水果手绘插画素材|一眼就想吃了!
  7. Java程序员不容错过的开发趋势
  8. java newtonsoft.json_Newtonsoft.Json(Json.Net)学习笔记
  9. 地区编码(定位中用到的编码)
  10. uniapp mescroll注意事项
  11. linux定时任务文件修改,linux 定时任务
  12. 内网渗透结束,痕迹清理必备手段
  13. 向量的点乘(内积、数量积)和叉乘(外积、向量积)
  14. 上井冲刺港交所上市:人均消费金额降幅明显,只在中国经营业务
  15. 顺丰开放平台开发者接入指引
  16. 首个可用于深度学习的ToF相关数据集!基于置信度的立体相机以及ToF相机深度图融合框架...
  17. CRF++安装教程(含Windows和Linux两个版本)
  18. RateLimiter实现限流
  19. 五子棋游戏Java代码简单实现(含活动图和类图设计)
  20. 网站排名超越竞争对手要做哪些策略?

热门文章

  1. 水电站泄洪监测预警系统解决方案
  2. 小程序地图实现+地图标点+获取实时定位
  3. python入门教程小学生_Python快速入门!为什么小学生都能学会Python,附python教程...
  4. Python之HTML解析
  5. ftp服务器登陆密码如何显示,ftp服务器登陆原始密码
  6. Love Letter(海角七号)
  7. CodeForces 630I Parking Lot (组合计数)
  8. python 按照句号拆分句子;Python 中re.split()方法
  9. 弘辽科技:抖音小店功效虚假宣传行为有哪些?
  10. 轻量级神经网络算法系列文章-MobileNet v3