其它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. api接口访问限制

    1.场景描述 在日常开发接口的时候,尤其是restfull接口,肯定会考虑安全或者是做一些自定义的限制,用来界定并维护代码.那么,我们都会采用什么方法那?通常来讲,我们可以通过session的形式,以 ...

  2. jmeter-逻辑控制器之 交替控制器(实现2个请求每次只执行其中一个)

    交替控制器: 案例:两个请求每次只能执行其中一个,可使用交替控制器. 1.线程组->添加->逻辑控制器->交替控制器 2.在控制下添加两个http请求.运行的时候第一次循环执行第一个 ...

  3. 如何阻止<a>标签的页面跳转

    当页面中a标签不需要执行任何页面跳转行为时: 1.标签属性href,使其指向空或不返回任何内容 <a href="javascript:void(0);" >页面不跳转 ...

  4. Docker容器构建过程的安全性分析

    来源:嘶吼专业版 ID:Pro4hou DevOps概念的流行跟近些年微服务架构的兴起有很大关系,DevOps是Dev(Development)和Ops(Operations)的结合,Dev负责开发, ...

  5. 事务隔离实现并发控制:MySQL系列之十

    一.并发访问控制 实现的并发访问的控制技术是基于锁: 锁分为表级锁和行级锁,MyISAM存储引擎不支持行级锁:InnoDB支持表级锁和行级锁: 锁的分类有读锁和写锁,读锁也被称为共享锁,加读锁的时候其 ...

  6. IE浏览器不支持Promise对象

    1. 安装babel-polyfill插件转换 npm install --save-dev babel-polyfill 2. 在webpack中引入babel-polyfill 在webpack. ...

  7. ajax异步请求问题

    今天在使用异步请求删除图片时,想在页面测试是不是有效果,使用halt完全没反应,我以为是AJAX请求地址有问题,没有请求到这个方法中,但是在控制台中network的请求地址是正常的,后来反应过来了,异 ...

  8. promise封装小程序的蓝牙类

    // pages/bluetooth/bluetooth.js import { BluetoothMode } from '../../models/bluetooth.js' import {Sy ...

  9. HTML 常用头部标签(meta)

    先来看下常用的标签列表,后文会一一介绍: <!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 --> <html lang=&quo ...

  10. Leetcode题解

    前言 Leetcode现在弄了一个Weekly Contest,然后题目又会作为新题目:感觉如果现在还不及时刷题的话可能真的赶不上它题目增长的速度了.......题目会在博客和Github上同步更新的 ...