| |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
-> C++知识库 -> 7-11 Saving James Bond - Easy/Hard Version (30 分) C语言实现 -> 正文阅读 |
|
[C++知识库]7-11 Saving James Bond - Easy/Hard Version (30 分) C语言实现 |
封校宅在寝室,开始肝图论算法题。题目思路如图,就是007在岛中,需要踩鳄鱼头(图中蓝点点)跳到岸。 坑点来搜csdn的一般都是卡测试点了,我简要说下这两题容易出现的错误(我自己遇到的): 首先这两题共同的就是,需要注意边界条件,可以把这个lake假象成一个框框,要注意跳到框框边缘部分也是属于安全地带!也就是说遇到<=-50或者>=50,都可以算safe了,所以可以检查一下自己的等于号有没有用错。 hard version的坑点在于:相比于easy需要考虑的更多了,写hard version的时候我才意识到自己easy应该忽略了很多条件,但奇迹般的AC了,主要是因为不考虑这些条件也影响输出结果。 这道题我采用了BFS+队列实现 容易出错的测试点: 测试点3:在记录鳄鱼的位置的时候要注意筛去那些在岛上的鳄鱼和在岸上的鳄鱼 测试点4:!我就是被这个卡了,要看清题意, ?If there are many shortest paths,just output the one with the minimum first jump 就是说在跳数一样的时候,要输出第一跳路径最短的而非进来序号最小的,所以一开始能第一跳的鳄鱼入队列之后需要根据路径长度排个序!!!我采用了qsort实现。 测试点5:就是说007腿很长,一跳就可以跳到岸,需要判断下,此时输出1。 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 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:
结尾无空行 Sample Output 1:
结尾无空行 Sample Input 2:
Sample Output 2:
Hard 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 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 a shortest path to reach one of the banks. The length of a path is the number of jumps that James has to make. 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, if James can escape, output in one line the minimum number of jumps he must make. Then starting from the next line, output the position?(x,y)?of each crocodile on the path, each pair in one line, from the island to the bank. If it is impossible for James to escape that way, simply give him 0 as the number of jumps. If there are many shortest paths, just output the one with the minimum first jump, which is guaranteed to be unique. Sample Input 1:
结尾无空行 Sample Output 1:
结尾无空行 Sample Input 2:
Sample Output 2:
代码实现写的代码并不是最好,有冗余,但是测试通过了。 Easy Version:
Hard Version:
? |
|
C++知识库 最新文章 |
【C++】友元、嵌套类、异常、RTTI、类型转换 |
通讯录的思路与实现(C语言) |
C++PrimerPlus 第七章 函数-C++的编程模块( |
Problem C: 算法9-9~9-12:平衡二叉树的基本 |
MSVC C++ UTF-8编程 |
C++进阶 多态原理 |
简单string类c++实现 |
我的年度总结 |
【C语言】以深厚地基筑伟岸高楼-基础篇(六 |
c语言常见错误合集 |
|
上一篇文章 下一篇文章 查看所有文章 |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 | -2024/11/24 9:24:43- |
|
网站联系: qq:121756557 email:121756557@qq.com IT数码 |