其它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. 匿名委托(方法) 以 ThreadStart 为例

    Hello Tec.   匿名委托(方法) 以 ThreadStart 为例 REF:http://baike.baidu.com/view/2761370.htm?fr=aladdin   不使用匿 ...

  2. 新安装的 ubuntu 下 make menuconfig 报错

    环境:Ubtuntu 12.04 LTS 新安装的ubuntu 出现不能使用make menuconfig. 1.sudo apt-get update 更新软件 2.安装下面的软件 sudo apt ...

  3. jqGrid 跨页选择以及回显的处理

    思路:定义全局的array(selectedIds),当列表选中的时候就push进去,当列表取消选中时,将该项从selectedIds中删除 重点:1.列表加载完成时为列表增加复选框,并给每一个che ...

  4. CF17E Palisection(回文自动机)

    题意翻译 给定一个长度为n的小写字母串.问你有多少对相交的回文子 串(包含也算相交) . 输入格式 第一行是字符串长度n(1<=n<=2*10^6),第二行字符串 输出格式 相交的回文子串 ...

  5. 74th LeetCode Weekly Contest Valid Number of Matching Subsequences

    Given string S and a dictionary of words words, find the number of words[i] that is a subsequence of ...

  6. Django - CRM项目(2)Q查询(模糊查询)

    一.CRM项目(2) 利用Q查询中的q对象完成条件筛选功能. 批量删除.公户转私户功能. 新增一张跟进记录表ConsultRecord,迁移数据库并添加测试数据,实现跟进记录列表页面. 客户列表新增跟 ...

  7. chapter06

    /** * Created by EX-CHENZECHAO001 on 2018-03-30. */class Chapter06 { } // 6 对象// 用对象作为单例或存放工具的方法// 类 ...

  8. Testlink安装配置时常见问题解决

    1.windows下安装testlink,进入安装页面后,在检查一些相关配置环境时报错,如下: Checking if /var/testlink/logs/ directory exists [S] ...

  9. 安装pywin32出现--Python version 3.x required, which was not found in the registry

    这两天安装pywin32时出现了这个问题 双击.exe文件进入安装界面,然后点击下一步,它会自动定位你的python安装在什么地方,但是我的安装过程中未自动定位到python安装位置,并显示显示: 安 ...

  10. Microsoft JDBC Driver 使用 getParameterMetaData 会报错?

    不知道为何使用 Microsoft JDBC Driver for SQL Server 驱动时,sql语句不带参数没有问题,但是如果带参数且使用 getParameterMetaData 就会提示某 ...