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 ...
随机推荐
- 新一代web框架Koa源码学习
此文已由作者张佃鹏授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. Koa 就是一种简单好用的 Web 框架.它的特点是优雅.简洁.表达力强.自由度高.本身代码只有1000多行 ...
- <富爸爸,穷爸爸> 书中的好句子
成为 做 拥有 资产是能把钱放进你口袋里的东西:负债是把钱从你的口袋里取走的东西. 语言会变成血肉,留在我们的身体里 要想做一个成功的投资者,你必须在情感上对赚钱和赔钱漠不关心,赚钱和赔钱只是游戏的一 ...
- burpsuite 抓HTTPS数据包
抓HTTPS数据包 导出保存为cer证书文件,导入到受信任的根证书颁发机构 设置代理服务器与burp中proxy listeners保持一致 设置目标url 抓包 可用repeater发请求
- 解读人:朱月琴,Hippocampal proteomic alteration in triple transgenic mouse model of Alzheimer’s disease and implication of PINK 1 regulation in donepezil treatment
文章中文名:阿尔茨海默病三联转基因小鼠模型的海马蛋白质组学改变及Donepezil治疗中PINK 1调节的意义 发表时间:(2019年4月) IF:3.95 单位:澳门大学,威斯康星大学,暨南大学,广 ...
- 如何阻止<a>标签的页面跳转
当页面中a标签不需要执行任何页面跳转行为时: 1.标签属性href,使其指向空或不返回任何内容 <a href="javascript:void(0);" >页面不跳转 ...
- HTTP header parsing errors will be logged at DEBUG level
-- ::-exec-] INFO org.apache.coyote.http11.Http11Processor - Error parsing HTTP request header Note: ...
- 阿里云服务器 linux 怎么安装php(PHPSTUDY)开发环境
1.首先登录行云管家(https://yun.cloudbility.com/login.html) wget -c http://lamp.phpstudy.NET/phpstudy.bin //下 ...
- Composite模式(组合设计模式)
Composite 设计模式? 在计算机的文件系统中,有"文件夹"的概念(在有些操作系统(Linux操作系统)中,也称为"目录").文件夹里面既可以放入文件,也 ...
- P2675 《瞿葩的数字游戏》T3-三角圣地
传送门 考虑最上面每个位置的数对答案的贡献 然后就很容易发现: 如果有n层,位置 i 的数对答案的贡献就是C( n-1,i ) 然后就有很显然的贪心做法: 越大的数放越中间,这样它的贡献就会尽可能的大 ...
- mysql执行计划 const eq_ref ref range index all
explain:查询查询性能或者需要查看使用索引状态 一.type:连接类型 最关键的一列 效率(const>eq_ref>ref>range>index>all) ...