博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Frogger
阅读量:4960 次
发布时间:2019-06-12

本文共 2922 字,大约阅读时间需要 9 分钟。

Description

Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists' sunscreen, he wants to avoid swimming and instead reach her by jumping.
Unfortunately Fiona's stone is out of his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach her by a sequence of several small jumps.
To execute a given sequence of jumps, a frog's jump range obviously must be at least as long as the longest jump occuring in the sequence.
The frog distance (humans also call it minimax distance) between two stones therefore is defined as the minimum necessary jump range over all possible paths between the two stones.
You are given the coordinates of Freddy's stone, Fiona's stone and all other stones in the lake. Your job is to compute the frog distance between Freddy's and Fiona's stone.

Input

The input will contain one or more test cases. The first line of each test case will contain the number of stones n (2<=n<=200). The next n lines each contain two integers xi,yi (0 <= xi,yi <= 1000) representing the coordinates of stone #i. Stone #1 is Freddy's stone, stone #2 is Fiona's stone, the other n-2 stones are unoccupied. There's a blank line following each test case. Input is terminated by a value of zero (0) for n.

Output

For each test case, print a line saying "Scenario #x" and a line saying "Frog Distance = y" where x is replaced by the test case number (they are numbered from 1) and y is replaced by the appropriate real number, printed to three decimals. Put a blank line after each test case, even after the last one.

Sample Input

20 03 4317 419 418 50

Sample Output

Scenario #1Frog Distance = 5.000Scenario #2Frog Distance = 1.414 题目大意:青蛙从A点跳到B点的所有路径中最长边的最小值(也就是哪一条通路里面的最长边相对其他通路中的最长边最小),也可以说成是最小生成树里 面的最大边。输出此最小值即可。 思路:题目就是求最小生成树中的最大边,即prim算法的灵活运用。就是在求最小生成树的过程当中,不断地去比较最小生成树的各边,当达到B点时就结 束查找 代码如下: #include
#include
#include
#include
#include
#include
using namespace std; double a[200][2]; double lowcost[200],closet[200]; double map[200][200]; int main() { int n; int k=1; while(cin>>n,n) { int i,j; for (i = 0 ;i < n ; i++ ) cin>>a[i][0]>>a[i][1]; memset(lowcost,0,sizeof(lowcost)); for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { map[i][j]=1.0*sqrt(pow(1.0*abs(a[i][0]-a[j][0]),2)+pow(1.0*abs(a[i][1]-a[j][1]),2)); } } double ans=0.0; for ( i = 0 ; i< n ; i++ )//先以点A为起点,将各点到A点的距离记录下来。 { lowcost[i]=map[0][i]; closet[i]=0; } for ( i = 0 ; i < n - 1 ; i ++ ) { double mindis=1.0*(1<<20); int minone; for ( j = 0 ; j < n ; j ++ ) { if(lowcost[j]&&mindis>lowcost[j]) //找到最短的边作为最小生成树的一部分 { mindis=lowcost[j]; minone=j; } } if(ans

转载于:https://www.cnblogs.com/441179572qqcom/p/5719498.html

你可能感兴趣的文章
restframework CBV试图的4种方式
查看>>
大图居中,以1920px为例
查看>>
Python3 图片转字符画
查看>>
[C陷阱和缺陷] 第7章 可移植性缺陷
查看>>
人需要治愈
查看>>
linux中configure文件默认执行结果所在位置
查看>>
Windows向Linux上传文件夹
查看>>
20180104-高级特性-Slice
查看>>
6个SQL Server 2005性能优化工具介绍
查看>>
nginx启动、关闭命令、重启nginx报错open() "/var/run/nginx/nginx.pid" failed
查看>>
BZOJ 3097 Hash Killer I
查看>>
UINavigationController的视图层理关系
查看>>
html阴影效果怎么做,css 内阴影怎么做
查看>>
宏观经济
查看>>
综合练习:词频统计
查看>>
BZOJ1026: [SCOI2009]windy数
查看>>
样板操作数
查看>>
64位UBUNTU下安装adobe reader后无法启动
查看>>
iTextSharp带中文转换出来的PDF文档显示乱码
查看>>
组件:slot插槽
查看>>