(DFS)PTA—Saving James Bond - Easy Version

PTA Saving James Bond - Easy Version 思路分析及代码解析 通过实践,你可以更好的理解图这种抽象数据结构,并运用图遍历解决实际问题 阅读详情

7-5 Saving James Bond - Easy Version (25 分)

This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land at the center of a lake filled with crocodiles. There he performed the most daring action to escape -- he jumped onto the head of the nearest crocodile! Before the animal realized what was happening, James jumped again onto the next big head... Finally he reached the bank before the last crocodile could bite him (actually the stunt man was caught by the big mouth and barely escaped with his extra thick boot).

Assume that the lake is a 100 by 100 square one. Assume that the center of the lake is at (0,0) and the northeast corner at (50,50). The central island is a disk centered at (0,0) with the diameter of 15. A number of crocodiles are in the lake at various positions. Given the coordinates of each crocodile and the distance that James could jump, you must tell him whether or not he can escape.

Input Specification:

Each input file contains one test case. Each case starts with a line containing two positive integers N (≤100), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the (x,y) location of a crocodile. Note that no two crocodiles are staying at the same position.

Output Specification:

For each test case, print in a line "Yes" if James can escape, or "No" if not.

Sample Input 1:

14 20
25 -15
-25 28
8 49
29 15
-35 -2
5 28
27 -29
-8 -28
-20 -35
-25 -20
-13 29
-30 15
-35 40
12 12

Sample Output 1:

Yes

Sample Input 2:

4 13
-12 12
12 12
-12 -12
12 -12

Sample Output 2:

No

这两个用例。。。 

 

PTA Saving James Bond - Hard Version 思路分析及代码解析 图的最短路径问题,可以在BFS的基础上加以解决 阅读详情

相关推荐

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

http://blog.youkuaiyun.com/xkzju2010/article/details/46458001

(c语言详解)06-图2 Saving James Bond - Easy Version

此题拯救007可谓是煞费苦心,没事就不要选择作死跳鳄鱼了。在矩阵初始化的时候将距离考虑进去,在BFS的时候一定要考虑距离因素,距离的表示方法还是看结构体数组。整体的代码捋顺就变得不是很难了。

执念斩长河 713

【杰理AC696X】ADKEY复用指示灯不定时出现灯不亮或按键失灵的问题

测试SDK版本:《ac696n_soundbox_sdk_v1.5.0-20211217》ADKEY复用指示灯的做法多用于蓝牙小音箱,IC引脚越来越少,复用也就用的越多了,不过,在使用前应评估好功能,因为复用的做法,肯定会牺牲点东西的,如果体验感啥的。 比如这个图,(V-)按键按下时,LED是会一直导通发光的,按不同阻值的按键还有亮度不一致的问题,这样的问题有的客户是不接受的,这就要另寻他法了。某天调好案子,放在一边测试时,发现指示灯不亮了,按键也不起作用,想起之前AC692系列也有类似的问题,很快就定位到

xx842678的博客 1656

06-图2 Saving James Bond - Easy Version( 拯救詹姆斯邦德)

This time let us consider the situation in the movie “Live and Let Die” in which James Bond, the world’s most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land ...

计算机科学与技术专业学生的成长之路 994

从零构建XVC协议栈:FPGA+W5300的跨界调试架构实战

本文详细介绍了如何从零构建XVC协议栈,通过FPGA与W5300以太网控制器的创新组合实现跨界调试架构。重点解析了JTAG时序逆向、TCP/IP协议栈集成与XVC协议实现,提供了硬件设计优化和性能加速技术,为嵌入式开发者和FPGA工程师提供实用的远程调试解决方案。

raspberrypi5的博客 251

【Origin+Python】使用External Python批量出图代码参考2

不使用part2 的代码,自己打开一个origin2022的界面。这里主要介绍一些进阶代码以及使用盗版origin要如何。3 批量绘制相同设置的曲线图。然后就是没有水印的图片了。

zeng001201的博客 1908

06-图2 Saving James Bond - Easy Version

06-图2 Saving James Bond - Easy Version 来自:https://pintia.cn/problem-sets/1211841066264109056/problems/1241660123425153025 This time let us consider the situation in the movie “Live and Let Die” in whi...

王寒寒的博客 229

springboot + netty 实现多客户端登录 超出设备 并下线

本文档旨在详细描述多平台登录控制的需求和实现方案。当前系统仅支持单设备登录,需扩展为支持多设备同时在线,并提供多种登录策略。文档详细列出四种策略:单平台登录、双平台登录、三平台登录和多平台同时在线,每种策略的具体限制和支持平台。技术实现方案包括数据结构设计、NettyUtils 工具类方法、WebSocketHandler 修改,以及相应的测试方案

Likefr 1880

【PTA】Saving James Bond - Easy Version (25 分)

#include <iostream> #include <algorithm> using namespace std; //存储每个点的x、y坐标 struct Node { int x; int y; }; #define MAXN 110 Node po[MAXN]; int Nv; int D; int flag=0; int visited[MAXN]; void FindEdge(int current){ visite...

fftx_00的博客 133

【实验必备】对AffectNet数据集进行人脸对齐的小Demo

本文首先简单介绍了AffectNet数据集,及人脸关键点等背景知识,接着Po出了人脸对齐的代码及效果展示。注:本文代码参考自FG2021的Emotion-GCN的开源代码,具有一定的可靠性,欢迎大家学习!

信小海 2675

【已解决】飞牛nas(fnOS)异常断电导致硬盘未挂载(无法挂载),系统内部错误修复、救回数据全流程!(含更新系统后外接 NTFS 格式硬盘丢失的修复方法)

fnOS 飞牛NAS遭遇非正常断电后,存储空间显示「未挂载」或更新系统后外接 NTFS 格式硬盘丢失,点击挂载提示「系统内部错误」!💥 博主已经完美恢复,本文记录了相关的解决方案,帮您恢复或最大程度保住重要数据🎉

XiaoqiangClub的博客 2328

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 Bond, the world’s most famous spy, was captured by a group of drug dealers. He was sent to a small piece of la...

weixin_43893847的博客 230

Opus Clip AI技术浅析(一)

Opus Clip AI 是一款由Opus公司推出的AI视频剪辑工具,旨在通过人工智能技术简化视频编辑过程,帮助用户快速从长视频中提取精彩片段,并生成适合社交媒体分享的短视频。

m0_75253143的博客 2155

7-10 Saving James Bond - Easy Version(DFS)

今天学习了DFS,于是做了一道PTA中关于DFS的习题,分享下! 思路来自浙大MOOC 文章目录题目思路代码 题目 先看一下题目: 这次让我们考虑一下电影《生死存亡》中的情况,其中,世界上最著名的间谍詹姆斯·邦德被一群毒贩抓获。他被送往位于充满鳄鱼的湖心的一小块土地上。在那儿,他执行了最大胆的行动以逃脱-他跳到最近的鳄鱼的头上!在动物意识到发生了什么之前,詹姆斯再次跳到下一个大脑袋上…终于,他在最...

Solomon的博客 409

dToF直方图之美_deadtime死区时间

IMX459的死区时间可以在6ns,这个时间是什么级别,车载激光雷达激光器的光脉宽一般都在4ns以上,也就是这个时间贴近去SPAD的死区时间,这就导致了pile up会非常弱,不会有太多数量的光子计数堆积,加上某些SPAD设计,对TDC有一些更深入的考量,所以不需要去校正pile up算法。Sensor层面决定了pile up的复杂程度,如果一个dToF的SPAD一致性非常好,那么pile up校正可以简单到极致,也就是一句代码的事,比如IMX611,优秀到不需要后端去考虑校正pile up。

致力于lidar应用开发 2152

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

PTA 06-图2 Saving James Bond - Easy Version

PTA 06-图2 Saving James Bond - Easy Version 原题链接 This time let us consider the situation in the movie “Live and Let Die” in which James Bond, the world’s most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land at the c

viVi_beea的博客 260

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

#数据结构与算法学习笔记#PTA19:拯救007基础版 Saving James Bond - Easy Version(Java)

2018.10.22 简单重述一下,James Bond被困在直径15的湖心岛上,整个湖可以模拟成一个100*100的矩阵,湖上有可供跳跃的陆地点(其实是鳄鱼背),每次007有一个最大的跳跃半径maxdist,问007能否成功逃脱跳到岸上。 这道题实际上是一道图题,但是却并不需要用邻接表或邻接矩阵建立一个图,只需要记录下所有可供跳跃的结点,把跳跃路径作为边,再进行一个简单的DFS,判断能够到达...

NJU_ChopinXBP的博客 597

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

PTA Saving James Bond - Easy Version 满分C++题解

#include <bits/stdc++.h> using namespace std; const int MaxN = 100; //N为鳄鱼数量,D为能跳跃的最大距离 int N, D; //int graph[MaxN][0]存x //int graph[MaxN][1]存y int graph[MaxN][2]; //监视器,查看是否跳过 bool vis[MaxN]; ...

qq_45455670的博客 315

pta 06-图2 Saving James Bond - Easy Version (25分) C语言实现

基本题意 This time let us consider the situation in the movie “Live and Let Die” in which James Bond, the world’s most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land at the center of a lake filled with crocodiles. The

xiejianhao1的博客 596

PTA数据结构-06-图2 Saving James Bond - Easy Version

一、题目 This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of...

hdu_ch的博客 301

浙大数据结构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 Bond, the world’s most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land at the center of a lake filled with crocodiles. There he

leslie___的博客 433

数据结构PTA习题:06-图2 Saving James Bond - Easy Version (25分)

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 Bond, the world’s most famous spy, was captured by a group of drug d...

wulila的博客 556

pta 编程题16 Saving James Bond - Easy Version

其它pta数据结构编程题请参见:pta 题目 主要用到了深度优先搜索。 1 #include <iostream> 2 using namespace std; 3 4 struct Vertex 5 { 6 int x; 7 int y; 8 bool marked; 9 }G[100]; 10 1...

weixin_38167855的博客 240

PTA-Saving James Bond - Easy Version

数据结构-图-C语言-PTA-Saving James Bond - Easy Version 以下为自己写的版本,难过的是测试点2无法通过 #include &amp;amp;amp;lt;stdio.h&amp;amp;amp;gt; #include &amp;amp;amp;lt;math.h&amp;amp;amp;gt; #define MaxSize 100 #define MinLength 42.5 bool answer = false

CaediosViolet的博客 392

【从0开始的刷题生活】PTA数据结构2019-秋 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 Bond, the world’s most famous spy, was captured by a group of drug dealers. He was sent to a small piece ...

qq_43576837的博客 444
上一篇: 欧拉回路—哥尼斯堡的“七桥问题”
下一篇: PTA—逆散列问题
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值