(poj 2253) Frogger 最短路上的最大路段
题目链接:http://poj.org/problem?id=2253
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 (<=n<=). The next n lines each contain two integers xi,yi ( <= xi,yi <= ) representing the coordinates of stone #i. Stone # is Freddy's stone, stone #2 is Fiona's stone, the other n- 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 ) 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 Sample Output Scenario #
Frog Distance = 5.000 Scenario #
Frog Distance = 1.414 Source
Ulm Local
题目大意:有一只青蛙想到另一只青蛙那,但是不能一次到位,他需要借助中间的石头跳跃,问他到另一只那走的最短路中的最长跳跃距离是多少?
方法:求到另一只青蛙的地方的最小生成树的最大距离。
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
#define met(a,b) memset(a,b,sizeof(a))
#define N 500
struct node
{
int x,y; }s[N];
int Map[N][N];
int dis[N],ans;
int vis[N];
void dij(int n)
{
met(vis,);
for(int i=;i<=n;i++)
dis[i]=Map[][i];
vis[]=;
for(int i=;i<n;i++)
{
int an=INF;
int k=-;
for(int j=;j<=n;j++)
{
if(!vis[j] && an>dis[j])
an=dis[k=j];
}
ans=max(ans,an);
if(k==)///当k==2已经到达另一只青蛙的坐标
return ;
vis[k]=;
for(int j=;j<=n;j++)
{
if(!vis[j])
dis[j]=min(dis[j],Map[k][j]);
} }
}
int main()
{
int n;
int con=;
while(scanf("%d",&n),n)
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
Map[i][j]=i==j?:INF;
}
for(int i=;i<=n;i++)
{
scanf("%d %d",&s[i].x,&s[i].y);
}
for(int i=;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
int ans=(s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y);
Map[i][j]=Map[j][i]=ans;
}
}
ans=-INF;
dij(n);
printf("Scenario #%d\n",con++);
printf("Frog Distance = %.3f\n\n",sqrt(ans));
}
return ;
}
(poj 2253) Frogger 最短路上的最大路段的更多相关文章
- 最短路(Floyd_Warshall) POJ 2253 Frogger
题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...
- POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)
POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...
- POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- POJ 2253 Frogger(dijkstra 最短路
POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...
- poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))
传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 Frogger
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- poj 2253 Frogger (dijkstra最短路)
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】
Frogger Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- POJ 2253 Frogger Floyd
原题链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
随机推荐
- Unity 琐碎(4) 可视化辅助调试Giamos
Gizmos 类 可以在代码中绘制一些输出结果或者中间输出内容,比如计算后的包围盒等等 类变量 方法 作用 color 控制输出颜色 matrix Set the gizmo matrix used ...
- Python编码问题小结
开门见山 decode的作用是将其他编码的字符串转换成Unicode编码,如str1.decode('gb2312'),表示将gb2312编码的字符串str1转换成Unicode编码. encode的 ...
- 《Java大学教程》—第12章 案例研究--第2部分
本章就是上一章的延续,主要是用GUI实现了控制界面. 编程练习:代码附件Hostel.java1. 正确运行2. Runhostel.java3. searchButton
- python六十四课——高阶函数练习题(二)
总结:高阶函数以及匿名函数之间的配合使用 from functools import reduce #模块一:lambda和filter的结合使用 #lt = [1,2,3,4,5,6,7,8,9] ...
- UVA1152-4 Values whose Sum is 0(分块)
Problem UVA1152-4 Values whose Sum is 0 Accept: 794 Submit: 10087Time Limit: 9000 mSec Problem Desc ...
- PHP设计模式_工厂模式
个人理解工厂类相当于平时用的基类,只需要把类new一次然后付给一个变量,以后直接引入基类调用变量使用类里的方法即可 了解 工厂模式,工厂方法或者类生成对象,而不是在代码中直接new. 使用工厂模式,可 ...
- 【angularjs】使用ionic+angular 搭建移动端项目,字体适配
解析: 首先,rem是以html为基准. 一般的,各大主流浏览器的font-size默认值为16px,此时1rem=16px.如果此时将rem与px进行换算很麻烦,比如0.75rem=12px. 为了 ...
- java 方法超时
public void getcd() { logger.info("任务开始!-------------------------------------"); final Exe ...
- 关于NOIP2018复赛若干巧合的声明
关于NOIP2018复赛若干巧合的声明 导言 参加NOIP2018时本人学龄只有两个月,却斩获了省一等奖,保送了重点中学的重点班,这看上去是个我创造的神话,然而,在我自己心中,我认为这只是个巧合(其实 ...
- Google Protocol Buffers学习
参考资料:http://www.cnblogs.com/royenhome/archive/2010/10/29/1864860.html 参考资料:http://www.jianshu.com/p/ ...