(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 ...
随机推荐
- python第一百一十天--Django 5
#####################################中间件################################################ settings.py ...
- 动态Linq表达式生成
动态构建 WHERE(C=>C.Id=Value): public static IQueryable<T> WhereEqual<T>(this IQueryable& ...
- python3 requests + BeautifulSoup 爬取阳光网投诉贴详情实例代码
用到了requests.BeautifulSoup.urllib等,具体代码如下. # -*- coding: utf-8 -*- """ Created on Sat ...
- mac os 10.12 Sierra 连接 惠普 M1136 MFP 打印机,通过 samba 协议,安装驱动,连接打印机
参考链接: https://support.hp.com/hk-zh/product/hp-zbook-17-g3-mobile-workstation/8693765/document/c04530 ...
- AppiumLibrary常用关键字
通过上一章节,open application关键字的使用,相信大家对手机自动化充满了兴趣,那么今天这一章节,主要介绍AppiumLibrary中常用关键字的使用. 一.实用函数 关键字 含义 实例 ...
- 使用 dep 配置 golang 开发环境
概要 golang 的包管理一直没有官方统一的解决方案,因此也产生了很多非官方的包管理工具. 之前我一直使用的 gb(https://getgb.io/) 能够很好的隔开各个 golang 工程,当时 ...
- May 24. 2018 Week 21st Thursday
Man errs so long as he strives. 失误是进取的代价. It is not important that the man in the arena didn't win, ...
- MATLAB—求直线或者线段之间的交点坐标
function CrossPoint( ) %% 求两条直线的交点坐标 x1 = [7.8 8]; y1 = [0.96 0.94]; %line2 x2 = [8.25 8.25]; y2 = [ ...
- 【Linux基础】VI命令模式下大小写转换
[开始位置] ---- 可以指定开始的位置,默认是光标的当前位置 gu ---- 把选择范围全部小写 gU ---- 把选择范围全部大写 [结束位置] ---- 可以跟着类似的w,6G,gg等定位到错 ...
- kafka-connect-hdfs重启,进去RECOVERY状态,从hadoop hdfs拿租约,很正常,但是也太久了吧
虽说这个算是正常现象,等的时间也太久了吧.分钟级了.这个RECOVERY里面的WAL有点多余.有这么久的时间,早从新读取kafka写入hdfs了.纯属个人见解. @SuppressWarnings(& ...