其它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的更多相关文章

  1. pta编程题19 Saving James Bond 2

    其它pta数据结构编程题请参见:pta 题目 和简单版本不同的是,简单版本只需判断能否到达岸边,而这个版本要求求出最少跳数的路径. 简单版本用dfs实现,而这道题用BFS实现. 注意: 岛半径为7.5 ...

  2. pat05-图2. Saving James Bond - Easy Version (25)

    05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...

  3. PAT Saving James Bond - Easy Version

    Saving James Bond - Easy Version This time let us consider the situation in the movie "Live and ...

  4. Saving James Bond - Easy Version (MOOC)

    06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...

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

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

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

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

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

随机推荐

  1. 字符串游戏(strgame)——博弈

    题目 [题目描述] pure 和 dirty 决定玩 $T$ 局游戏.对于每一局游戏,有 $n$ 个字符串,并且每一局游戏由 $K$ 轮组成.具体规则如下:在每一轮游戏中,最开始有一个空串,两者轮流向 ...

  2. Problem C: [noip2016十连测第五场]travel (构造+贪心)

    题面 https://www.lydsy.com/JudgeOnline/upload/201610/statements(1).pdf 题解 好神仙的贪心-- 首先无解的情况很容易判断,就是\(l= ...

  3. BadBoy录制模式:Request 和 Navigation比较

    [前言] 今天来为大家介绍下BadBoy录制模式: Request 和 Navigation的比较! 如果您的电脑还未安装BadBoy这款工具的话,可以参考下BadBoy安装步骤和简单介绍:http: ...

  4. 根据T-Code查看用户出口的代码

    在此非常非常感谢源作者,这段代码真的非常非常有用好用! REPORT  YLBTEST. TABLES :  tstc,     "SAP Transaction Codes(SAP 事务代 ...

  5. 帝都Day4(1)——还是dp

    其实是day4 一.洛谷P1018 乘积最大 f[i][j]表示前i个数 切成j块 用f[i][j]而不用f[i][j][k](i到j切成k块)呢? Luogu1043 前缀和(好算一段里的数的和)+ ...

  6. 自定义标签报 无法为TAG [my2:hello]加载标记处理程序类[null]

    今天练习jsp自定义标签的时候,等我写好全部和检查万无一失的时候.执行然后报错了 无法为TAG [my2:hello]加载标记处理程序类[null] 我反复检查代码,发现代码也没什么问题.后面通过百度 ...

  7. C 语言实例 - 实现简单的计算器

    C 语言实例 - 实现简单的计算器 实现加减乘除计算. 实例 # include <stdio.h> int main() { char operator; double firstNum ...

  8. PIE使IE浏览器支持CSS3属性(圆角、阴影、渐变)

    http://www.360doc.com/content/12/1214/09/11181348_253939277.shtml PIE使IE浏览器支持CSS3属性(圆角.阴影.渐变) 2012-1 ...

  9. Python——连接数据库

    好用的教程(*^▽^*):https://www.cnblogs.com/fatcat132006/p/4081576.html

  10. jquery click嵌套 事件重复注册 多次执行的问题

    jquery click嵌套 事件重复注册 多次执行的问题 上面只是参考,我自己的解决方法是先使用unbind("click")解除事件然后再绑定新事件: $("#tes ...