(模拟+floyd)Saving James Bond

题目:

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×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 he could escape.If he could,tell him the shortest length he has to jump and the min-steps he has to jump for shortest length.
Input
The input consists of several test cases. Each case starts with a line containing n <= 100, the number of crocodiles, and d > 0, the distance that James could jump. Then one line follows for each crocodile, containing the (x, y) location of the crocodile. Note that x and y are both integers, and no two crocodiles are staying at the same position.
Output
For each test case, if James can escape, outp**ut in one line the shortest length he has to jump** and the min-steps he has to jump for shortest length. If it is impossible for James to escape that way, simply ouput “can’t be saved”.
Sample Input
4 10
17 0
27 0
37 0
45 0
1 10
20 30
Sample Output
42.50 5
can’t be saved

题意:鳄鱼的坐标,n是鳄鱼的数目,d是一步跳的最远距离
题目输出他走到终点需要的最小距离,还有最小的距离中走的最小的步数
这里写图片描述

参考代码:
https://blog.csdn.net/libin56842/article/details/17034011
实现起来有点崩溃

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
const double inf = 100000000;
double map[105][105];
int s[105],e[105],step[105][105],len1,len2;struct node
{double x,y;
} a[105];void floyd(int n)
{int i,j,k;for(k = 0; k<=n; k++)for(i = 0; i<=n; i++)for(j = 0; j<=n; j++)if(map[i][j]>map[i][k]+map[k][j]){map[i][j]=map[i][k]+map[k][j];step[i][j]=step[i][k]+step[k][j];}
}int main()
{int n,i,j,k,len;double d,x,y;while(~scanf("%d%lf",&n,&d)){len = 1;for(i = 1; i<=n; i++){scanf("%lf%lf",&x,&y);if(fabs(x)<=7.5 && fabs(y)<=7.5)//只将所有在小岛外的点存入图中continue;a[len].x = x;a[len++].y = y;}n = len;if(n == 1)//只存了一个点,直接判断{if(d>=42.5)printf("42.50 1\n");elseprintf("can't be saved\n");continue;}for(i = 0; i<=n; i++)for(j = 0; j<=n; j++){map[i][j] = inf;step[i][j] = 0;}for(i = 1; i<n; i++){for(j = 1; j<n; j++){if(j==i){map[i][j] = 0;continue;}map[i][j] = sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));//枚举所有距离step[i][j] = 1;if(map[i][j]>d)//步伐不能到达,将该店变为无穷大{map[i][j] = inf;step[i][j] = 0;}}}len1 = len2 = 0;for(i = 1; i<n; i++){if(sqrt(a[i].x*a[i].x+a[i].y*a[i].y)<=7.5+d)//起始点必须是从小岛上出发,步伐能到达的点s[len1++] = i;if((50+a[i].x)<=d || (50-a[i].x)<=d || (50+a[i].y)<=d || (50-a[i].y)<=d)//借速点市所有能到达岸边的点e[len2++] = i;}for(i = 0; i<len1; i++){map[0][s[i]] = map[s[i]][0] = sqrt(a[s[i]].x*a[s[i]].x+a[s[i]].y*a[s[i]].y)-7.5;//小岛到起始点的距离step[0][s[i]] = step[s[i]][0] = 1;}for(i = 0; i<len2; i++){map[e[i]][n] = map[n][e[i]] = min(min(50+a[e[i]].x,50-a[e[i]].x),min(50+a[e[i]].y,50-a[e[i]].y));//结束点到岸边的最短距离step[e[i]][n] = step[n][e[i]] = 1;}floyd(n);if(map[0][n] == inf)printf("can't be saved\n");elseprintf("%.2f %d\n",map[0][n],step[0][n]);}return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/560699.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

(dijkstra算法+多权值)最短路径问题

给你n个点&#xff0c;m条无向边&#xff0c;每条边都有长度d和花费p&#xff0c;给你起点s终点t&#xff0c;要求输出起点到终点的最短距离及其花费&#xff0c;如果最短距离有多条路线&#xff0c;则输出花费最少的。 Input 输入n,m&#xff0c;点的编号是1~n,然后是m行&am…

php 取经纬度,php根据地址获取百度地图经纬度的实例方法

首先我们来看全部实例代码&#xff1a;/*** param string $address 地址* param string $city 城市名* return array*/function getLatLng($address‘‘,$city‘‘){$result array();$ak ‘‘;//您的百度地图ak&#xff0c;可以去百度开发者中心去免费申请$url "http://…

php 留言板分页显示,php有分页的留言板,留言成功后怎么返回当前页?

比如我在【index.php?p3】发布留言&#xff0c;成功后怎么返回到 index.php?p3 这个页面&#xff1f;在【index.php?p5】发布留言成功后怎么返回index.php?p5这个页面&#xff1f;location.href"这里该怎么写&#xff1f;"涉及的页面有index.php&#xff0c;doac…

php class使用方法,PHP调试类Krumo使用教程

写程序最讨厌的是程序发生错误&#xff0c;但是却又不知道该从何debug起&#xff0c;我们通常会使用print_r 或者 var_dump 或者是 echo 慢慢的debug。如果你跟我一样使用PHP 5开发&#xff0c;现在可以使用Krumo这个简单好用的工具帮助我们做这件事情。虽然IDE也有内建的debug…

matlab 连接数组,matlab数组操作知识点总结

其实如果单从建模来讲&#xff0c;以下大部分函数都用不到&#xff0c;但是这些都是基础。第一点&#xff1a;数组与矩阵概念的区分数组&#xff1a;与其它编程语言一样&#xff0c;定义是&#xff1a;相同数据类型元素的集合。矩阵&#xff1a;在数学中&#xff0c;矩阵(Matri…

(组合数求模=乘法逆元+快速幂) Problem Makes Problem

题目&#xff1a; As I am fond of making easier problems, I discovered a problem. Actually, the problem is ‘how can you make n by adding k non-negative integers?’ I think a small example will make things clear. Suppose n4 and k3. There are 15 solutions.…

(小费马定理降幂)Sum

题目&#xff1a; 分析与解答&#xff1a; 参考思路&#xff1a; https://www.cnblogs.com/stepping/p/7144512.html https://blog.csdn.net/strangedbly/article/details/50996908 根据隔板定理&#xff0c;把N分成一份的分法数为C(1,n-1)&#xff0c; 把N分成两份的分法…

matlab 参数识别,[转载]自编最小二乘法的Matlab参数辨识程序(含实例)

function [sysd,sys,err] ID(Y,U,Ts)%%基于递推最小二乘法的参数辨识程序%仅针对二阶系统&#xff1a;)%出处&#xff1a;http://blog.sina.com.cn/xianfa110%---------------%Inputs:%---------------%Y nX1 vector of your model output%U nX1 vector of your model input…

让apache解析html里的php代码,让Apache解析html文件中的php语句

为什么要干这种事呢&#xff1f;原因在于:对于纯粹的网页来说(不涉及对于数据库的操作)&#xff0c;可以使用一些软件来生成html代码。推荐软件Axure但是&#xff0c;当生成html文件之后&#xff0c;你发现还要写php语句对数据库进行操作时&#xff0c;就会遇到一些问题。首先&…

(lucas) Saving Beans

题目&#xff1a; Although winter is far away, squirrels have to work day and night to save beans. They need plenty of food to get through those long cold days. After some time the squirrel family thinks that they have to solve a problem. They suppose that…

(矩阵快速幂)解所有类似Fibonacci 的题目

Description In the Fibonacci integer sequence, F0 0, F1 1, and Fn Fn − 1 Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … An alternative formula for the Fibonacci sequence is Gi…

php getdbused,PHP之购物车

该文章记录了购物车的实现代码&#xff0c;仅供参考book_sc_fns.phpinclude_once(output_fns.php);include_once(book_fns.php);include_once(db_fns.php);include_once("user_auth_fns.php");include_once("admin_fns.php");include_once("data_vali…

2018.9.15,Arduino—流水灯实验报告

实验任务和目的 通过Arduino控制LED形成流水灯效果 实验条件 Arduino UNO&#xff0c;面包板&#xff0c;6个LED&#xff0c;6个220Ω电阻 实验过程和结果 实验详细步骤&#xff1a; 在各LED正极和Arduino引脚之间串联一个限流电阻&#xff0c;并将LED负极与Arduion的GND相连 …

2018.9.10.Matlab实验一:熟悉Matlab开发环境

一、实验任务和目的 1. 熟悉Matlab的系统环境及基本操作方法。 2. 掌握Matlab的搜索路径及其设置方法。 3. 熟悉Matlab的帮助信息的查阅方法。 二、实验内容 1. 熟悉 Matlab 工作界面的多个常用窗口的及使用方法。 熟悉Command windows、Workspace、Command history、C…

2018.9.10.Matlab实验二:Matlab基本运算

实验二&#xff1a;Matlab基本运算 一、实验任务和目的 1. 掌握变量的定义与数据类型。 2. 掌握变量的初始化方法。 3. 掌握数组、多维数组与子数组的定义、存储、赋值、变换。 4. 掌握逻辑数组的用法。 5. 熟悉MATLAB常用的函数、常用标点和快捷键。 二、实验内容 1. …

2018.9.15,Matlab实验三:字符串、单元数组和结构体

一、实验任务和目的 掌握Matlab的字符串常用函数及其操作方法。掌握Matlab的结构体的基本操作方法。掌握Matlab的元胞数组的基本操作方法。 二、实验内容字符串数组Str[‘hopes, dreams, hold up, old up’]&#xff0c;查找’O’出现的次数和位置。现有三个字符串变量s1“i”…

c++ 不能分配给为0的数组_【嵌入式C】你有想过quot;数组下标quot;为何从0开始吗?...

1、聊一聊相信大家都有看过电影&#xff0c;今天所分享的是其经典背景音乐&#xff0c;或许音乐响起你又会想起那条单纯、善良的秋田犬&#xff01;今天跟大家聊聊一个有意思的话题&#xff0c;C中的数组下标为啥是从0开始?或者说为什么现在大部分的编程语言都会选择从0开始索…

2018.9.19.Matlab实验四:Matlab程序设计

一、实验任务和目的 熟悉程序设计思想。掌握伪代码的编写方法。掌握分支语句和循环结构的用法。 二、实验内容 输入一个百分制成绩&#xff0c;要求输出成绩等级A、B、C、D、E&#xff0c;其中90-100为A&#xff0c;80-89为B&#xff0c;70-79为C&#xff0c;60-69为D&#…

sata接口 图解 定义_SATA协议简介

SATA协议简介1、概述本文档主要介绍SATA的发展历程以及SATA相关协议&#xff0c;为后续SATA驱动框架分析做基础知识准备。2、SATA简介2.1 SATA发展历程2.1.1 PATA硬盘PATA硬盘叫做并行ATA硬盘(Parellel ATA)。为了限制其信号放大系统产生的高噪声&#xff0c;常采用高达5V的电压…