pta 编程题16 Saving James Bond - Easy Version
其它pta数据结构编程题请参见:pta
主要用到了深度优先搜索。
#include <iostream>
using namespace std; struct Vertex
{
int x;
int y;
bool marked;
}G[]; int N; //总鳄鱼数
int D; //可以跳的距离
bool dfs(Vertex& v);
bool firstJump(Vertex v);
bool jump(Vertex v1, Vertex v2);
bool success(Vertex v); //可以跳到岸上 int main()
{
int i;
cin >> N >> D;
for (i = ; i < N; i++)
cin >> G[i].x >> G[i].y; bool canEscape = false;
for (i = ; i < N; i++)
{
if (!G[i].marked && firstJump(G[i]))
canEscape = dfs(G[i]);
if (canEscape) break;
}
if (canEscape) cout << "Yes";
else cout << "No";
return ;
} bool firstJump(Vertex v)
{
return v.x * v.x + v.y * v.y <= ( + D) * ( + D);
} bool dfs(Vertex& v)
{
bool canEscape = false;
v.marked = true;
if (success(v)) return true;
for (int i = ; i < N; i++)
{
if (!G[i].marked && jump(v, G[i]))
canEscape = dfs(G[i]);
if (canEscape) break;
}
return canEscape;
} bool success(Vertex v)
{
if (v.x <= D - || v.x >= - D || v.y <= D - || v.y >= - D)
return true;
return false;
} bool jump(Vertex v1, Vertex v2)
{
return (v1.x - v2.x) * (v1.x - v2.x) + (v1.y - v2.y) * (v1.y - v2.y) <= D*D;
}
pta 编程题16 Saving James Bond - Easy Version的更多相关文章
- pta编程题19 Saving James Bond 2
其它pta数据结构编程题请参见:pta 题目 和简单版本不同的是,简单版本只需判断能否到达岸边,而这个版本要求求出最少跳数的路径. 简单版本用dfs实现,而这道题用BFS实现. 注意: 岛半径为7.5 ...
- pat05-图2. Saving James Bond - Easy Version (25)
05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...
- PAT Saving James Bond - Easy Version
Saving James Bond - Easy Version This time let us consider the situation in the movie "Live and ...
- Saving James Bond - Easy Version (MOOC)
06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...
- 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 ...
- PTA 06-图2 Saving James Bond - Easy Version (25分)
This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...
- 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 ...
- 06-图2 Saving James Bond - Easy Version (25 分)
This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...
- 06-图2 Saving James Bond - Easy Version (25 分)
This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...
随机推荐
- 【maven setting.xml】
<!--声明语句--> <?xml version="1.0" encoding="UTF-8"?> <settings xmln ...
- .net Core命令行,Json配置
创建.netCore控制台 NuGet :Microsoft.AspNetCore.All static void Main(string[] args) { var builder = new Co ...
- ApiDoc 一键生成注释
本文来自网易云社区. 作者:盛国存 背景 我们日常在使用ApiDoc维护管理api文档,提高了api文档的整体维护性.但在老旧接口中,补充接口注解无疑是一次繁重的体力劳动.仔细查看,大多数接口的格式 ...
- PHP中的继承
<?php class Bar { private $salary = 3000; public $lunch = 1000; // php中关于“可见性”的概念 public function ...
- How to modify rosbag?如何修改rosbag?
Ubuntu16.04,kinetic 本文示例修改使用rosbag中的frame id 在http://wiki.ros.org/bag_tools中,能找到 change_camera_info. ...
- [Xcode 实际操作]三、视图控制器-(9)在Storyboard中使用标签和按钮控件
目录:[Swift]Xcode实际操作 本文将演示标签和按钮在故事板中的应用. 在欢迎串口中,点击创建一个新的项目[Create a new Xcode project] [Single View A ...
- PAT天梯赛L2-008 最长对称字符串
题目链接:点击打开链接 对给定的字符串,本题要求你输出最长对称子串的长度.例如,给定"Is PAT&TAP symmetric?",最长对称子串为"s PAT&a ...
- 设置Input标签Date默认值为当前时间
需求:想设置Imput标签Date默认值为当前时间,通过JavaScript实现. <html> ...... <body> <input type="date ...
- CSS(一)清除浮动
问题1:关于清除浮动 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- BZOJ 1500 [NOI2005]维修数列 FHQ Treap
终于A了这题...这题还是很好...但是我太菜...重构了三遍qwq FHQ Treap大法好!qwq...~~ Ins:直接拿输入造一棵树,把原来的树split成[1,pos],[pos+1,n], ...