07-图5 Saving James Bond - Hard Version (30分)

2023-12-09 12:08
文章标签 30 version 07 hard bond james saving

本文主要是介绍07-图5 Saving James Bond - Hard Version (30分),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

07-图5 Saving James Bond - Hard Version (30分)

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:

17 15
10 -21
10 21
-40 10
30 -50
20 40
35 10
0 -10
-25 22
40 -40
-30 30
-10 22
0 11
25 21
25 10
10 10
10 35
-30 10

Sample Output 1:

4
0 11
10 21
10 35

Sample Input 2:

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

Sample Output 2:

0

#include<bits/stdc++.h>
using namespace std;
struct Node {double x, y;double distant;int c;
};
struct TS {int num;double distant;
};TS HHH[105];
int N, path[105];
double D, G[105][105];
Node Dist[105];
bool visit[105] = {false};void Init(int i, int j);
int BFS(int i);
int Judge(int i);
bool cmp(TS a, TS b) {return a.distant < b.distant;
}int main() {cin >> N >> D;if (D >= 32.5) {printf("1\n");return 0;}int X, Y;int tol = 0;fill(G[0], G[0] + 105*105, 200);for (int i = 0; i < N; i++) {cin >> X >> Y;HHH[i].num = i;Dist[i].x = X;Dist[i].y = Y;Dist[i].distant = sqrt(X * X + Y * Y);HHH[i].distant = Dist[i].distant;Dist[i].c = 0;path[i] = -1;}for (int i = 0; i < N - 1; i++) {for (int j = i + 1; j < N; j++) {Init(i, j);}}sort(HHH, HHH + N, cmp);for (int i = 0; i < N; i++) {if (HHH[i].distant > 7.5 && HHH[i].distant <= D + 7.5 && !visit[HHH[i].num]) {tol = BFS(HHH[i].num);if (tol > 1) break;}}if (tol == 0) printf("0\n");return 0;
}void Init(int i, int j) {int x = Dist[i].x - Dist[j].x;int y = Dist[i].y - Dist[j].y;G[i][j] = G[j][i] = sqrt(x * x + y * y);
}int Judge(int i) {if ((Dist[i].x + D >= 50) || (Dist[i].x - D <= -50) || (Dist[i].y + D >= 50) || (Dist[i].y - D <= -50)) return 1;else return 0;
}int BFS(int i) {visit[i] = true;Dist[i].c = 1;queue<int> Q;Q.push(i);while (!Q.empty()) {int temp = Q.front();Q.pop();if (Judge(temp)) {cout << Dist[temp].c + 1 << endl;stack<int> st;while (temp != -1) {st.push(temp);temp = path[temp];}while (!st.empty()) {int Top = st.top();st.pop();cout << Dist[Top].x << " " << Dist[Top].y << endl;}return 2;}for (int i = 0; i < N; i++) {if (G[temp][i] <= D && !visit[i]) {visit[i] = true;Dist[i].c = Dist[temp].c + 1;path[i] = temp;Q.push(i);}}}return 0;
}

这篇关于07-图5 Saving James Bond - Hard Version (30分)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/473704

相关文章

30常用 Maven 命令

Maven 是一个强大的项目管理和构建工具,它广泛用于 Java 项目的依赖管理、构建流程和插件集成。Maven 的命令行工具提供了大量的命令来帮助开发人员管理项目的生命周期、依赖和插件。以下是 常用 Maven 命令的使用场景及其详细解释。 1. mvn clean 使用场景:清理项目的生成目录,通常用于删除项目中自动生成的文件(如 target/ 目录)。共性规律:清理操作

2024网安周今日开幕,亚信安全亮相30城

2024年国家网络安全宣传周今天在广州拉开帷幕。今年网安周继续以“网络安全为人民,网络安全靠人民”为主题。2024年国家网络安全宣传周涵盖了1场开幕式、1场高峰论坛、5个重要活动、15场分论坛/座谈会/闭门会、6个主题日活动和网络安全“六进”活动。亚信安全出席2024年国家网络安全宣传周开幕式和主论坛,并将通过线下宣讲、创意科普、成果展示等多种形式,让广大民众看得懂、记得住安全知识,同时还

Maven创建项目中的groupId, artifactId, 和 version的意思

文章目录 groupIdartifactIdversionname groupId 定义:groupId 是 Maven 项目坐标的第一个部分,它通常表示项目的组织或公司的域名反转写法。例如,如果你为公司 example.com 开发软件,groupId 可能是 com.example。作用:groupId 被用来组织和分组相关的 Maven artifacts,这样可以避免

07 v-if和v-show使用和区别

划重点: v-ifv-show 小葱拌豆腐 <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="

c++习题30-求10000以内N的阶乘

目录 一,题目  二,思路 三,代码    一,题目  描述 求10000以内n的阶乘。 输入描述 只有一行输入,整数n(0≤n≤10000)。 输出描述 一行,即n!的值。 用例输入 1  4 用例输出 1  24   二,思路 n    n!           0    1 1    1*1=1 2    1*2=2 3    2*3=6 4

Jenkins 通过 Version Number Plugin 自动生成和管理构建的版本号

步骤 1:安装 Version Number Plugin 登录 Jenkins 的管理界面。进入 “Manage Jenkins” -> “Manage Plugins”。在 “Available” 选项卡中搜索 “Version Number Plugin”。选中并安装插件,完成后可能需要重启 Jenkins。 步骤 2:配置版本号生成 打开项目配置页面。在下方找到 “Build Env

Learn ComputeShader 09 Night version lenses

这次将要制作一个类似夜视仪的效果 第一步就是要降低图像的分辨率, 这只需要将id.xy除上一个数字然后再乘上这个数字 可以根据下图理解,很明显通过这个操作在多个像素显示了相同的颜色,并且很多像素颜色被丢失了,自然就会有降低分辨率的效果 效果: 但是这样图像太锐利了,我们加入噪声去解决这个问题 [numthreads(8, 8, 1)]void CSMain(uint3 id

嵌入式面试经典30问:二

1. 嵌入式系统中,如何选择合适的微控制器或微处理器? 在嵌入式系统中选择合适的微控制器(MCU)或微处理器(MPU)时,需要考虑多个因素以确保所选组件能够满足项目的具体需求。以下是一些关键步骤和考虑因素: 1.1 确定项目需求 性能要求:根据项目的复杂度、处理速度和数据吞吐量等要求,确定所需的处理器性能。功耗:评估系统的功耗需求,选择低功耗的MCU或MPU以延长电池寿命或减少能源消耗。成本

【全网最全】2024年数学建模国赛A题30页完整建模文档+17页成品论文+保奖matla代码+可视化图表等(后续会更新)

您的点赞收藏是我继续更新的最大动力! 一定要点击如下的卡片,那是获取资料的入口! 【全网最全】2024年数学建模国赛A题30页完整建模文档+17页成品论文+保奖matla代码+可视化图表等(后续会更新)「首先来看看目前已有的资料,还会不断更新哦~一次购买,后续不会再被收费哦,保证是全网最全资源,随着后续内容更新,价格会上涨,越早购买,价格越低,让大家再也不需要到处买断片资料啦~💰💸👋」�

JobScheduler 调用导致的运行时长30分钟的功耗问题

一、SDK 的使用情况与功耗影响 案例是否导致功耗变大onStartJob return true 且子线程没有调用jobFinished()告知系统功耗变大,最长带来30分钟的partial wakelock 长持锁onStartJob return true 且子线程调用jobFinished()告知系统功耗有影响,主要线程执行时长,标准是30秒内onStartJob return fals