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

2
0 0
3 4 3
17 4
19 4
18 5 0

Sample Output

Scenario #1
Frog Distance = 5.000 Scenario #2
Frog Distance = 1.414 题目大意:第一个点是起点 ,第二个点是终点其余点是起点和终点之间的点,问从起点到终点最短路上两点之间最远的距离。
这是一个最短路变形问题,dis数组保存的不再是到某一点的最短路径,而是路径上两点之间的最远距离
转移方程dis[i]=min(dis[i],max(ans,arr[pos][i]))
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int N=1e4+;
const double INF=1e7+;
int n;
struct stu{
int a,b;
}p[N];
int mark[N];
double arr[N][N];
double dis[N];
void djstrea(){
memset(mark,,sizeof(mark));
for(int i=;i<=n;i++){
dis[i]=arr[][i];
}
dis[]=;
mark[]=;
for(int i=;i<=n;i++){
double ans=INF;
int s;
for(int i=;i<=n;i++)
if(mark[i]==&&ans>dis[i]){
ans=dis[i];
s=i;
}
mark[s]=;
for(int i=;i<=n;i++){
if(mark[i]==){
dis[i]=min(dis[i],max(ans,arr[s][i]));//转移方程变啦
}
}
}
}
int main(){
int k=;
int x,y;
while(scanf("%d",&n)&&n){
k++;
for(int i=;i<=n;i++){
cin>>x>>y;
p[i].a=x;
p[i].b=y;
}
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
arr[i][j]=arr[j][i]=INF; for(int i=;i<n;i++){
for(int j=i+;j<=n;j++){
arr[j][i]=arr[i][j]=sqrt((p[i].a-p[j].a)*(p[i].a-p[j].a)+(p[i].b-p[j].b)*(p[i].b-p[j].b));
}
}
djstrea();
printf("Scenario #%d\n",k);
printf("Frog Distance = %.3f\n",dis[]);
cout<<endl;
}
return ;
}

也可以用flord写:

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define maxnum 300
#define inf 0x3f3f3f3f
using namespace std;
int x[maxnum],y[maxnum],n;
double map[maxnum][maxnum];
void floyd()
{
for(int k=; k<=n; k++)
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
map[i][j]=min(map[i][j],max(map[i][k],map[k][j]));//许多通路中最长边中的最小边
// map[i][j]=min(map[i][j],max(map[i][k],map[k][j]));
}
int main()
{
int q=;
while(~scanf("%d",&n)&&n)
{
mem(map,);
for(int i=; i<=n; i++)
scanf("%d%d",&x[i],&y[i]);
for(int i=; i<=n; i++)
for(int j=i+; j<=n; j++)
map[i][j]=map[j][i]=sqrt(double(x[i]-x[j])*(x[i]-x[j])+double(y[i]-y[j])*(y[i]-y[j]));
floyd();
printf("Scenario #%d\nFrog Distance = %.3lf\n\n",q++,map[][]);
}
return ; }
												

最短路径变形 POJ 2253的更多相关文章

  1. poj 2253 (dis最短路径)

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24979   Accepted: 8114 Descript ...

  2. poj 2253 Frogger (最长路中的最短路)

    链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...

  3. 最短路(Floyd_Warshall) POJ 2253 Frogger

    题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...

  4. POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)

    POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...

  5. POJ. 2253 Frogger (Dijkstra )

    POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...

  6. POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】

    Frogger Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  7. POJ 2253 Frogger(dijkstra 最短路

    POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...

  8. POJ 2253 Frogger(Dijkstra变形——最短路径最大权值)

    题目链接: http://poj.org/problem?id=2253 Description Freddy Frog is sitting on a stone in the middle of ...

  9. [ACM] POJ 2253 Frogger (最短路径变形,每条通路中的最长边的最小值)

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24879   Accepted: 8076 Descript ...

随机推荐

  1. 题解 P2070 【刷墙】

    前言 \(ZHK\)私人博客体验更佳 这道题目,\(n<=10^5\),显然在暗示我们使用\(n \log n\)的做法,我就是用了一个简单的贪心,通过了此题. 正文 在这道题中,我们发现,可以 ...

  2. innobackupex备份过程(有图有真相)

    innobackupex命令构成: 1. Innobackupex内部封装了xtrabackup和mysqldump命令: 2. Xtrabackup是用来备份innoDB表的,内部实现对innoDB ...

  3. 结构化学习(Structured Learning)

    本博客是针对李宏毅教授在youtube上上传的Machine Learning课程视频的学习笔记.课程链接 目录 引入 线性模型 结构化SVM 给序列贴标签 引入 我们之前学习到的学习模型的输入与输出 ...

  4. BFS与DFS常考算法整理

    BFS与DFS常考算法整理 Preface BFS(Breath-First Search,广度优先搜索)与DFS(Depth-First Search,深度优先搜索)是两种针对树与图数据结构的遍历或 ...

  5. 一夜搞懂 | JVM 类加载机制

    前言 本文已经收录到我的Github个人博客,欢迎大佬们光临寒舍: 我的GIthub博客 学习导图 一.为什么要学习类加载机制? 今天想跟大家唠嗑唠嗑Java的类加载机制,这是Java的一个很重要的创 ...

  6. 最大子矩阵hdu1559(二维前缀和)

    最大子矩阵hdu1559 Problem Description 给你一个m×n的整数矩阵,在上面找一个x×y的子矩阵,使子矩阵中所有元素的和最大. Input 输入数据的第一行为一个正整数T,表示有 ...

  7. PTA | 1019 数字黑洞 (20分)

    给定任一个各位数字不完全相同的 4 位正整数,如果我们先把 4 个数字按非递增排序,再按非递减排序,然后用第 1 个数字减第 2 个数字,将得到一个新的数字.一直重复这样做,我们很快会停在有" ...

  8. Pytest系列(11)- 失败重跑插件pytest-rerunfailures详细使用

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 环境前提 以下先决条件才能使用py ...

  9. 【PHP】PHP基本语法

    一.什么是PHP? a)    定义:PHP就是超文本预处理器 b)    超文本:我们前边8天学习的内容其实就是超文本内容 c)    预处理器:相当于牛奶在工厂加工的过程,我们虽然不可见,但是我们 ...

  10. 家庭版记账本app进度之对于按钮的点击事件以及线性布局以及(alertdialog)等相关内容的应用测试

    通过线性布局,制作出连个按钮还有文本输入框以及嘴上放的标题文本进行信息的相关显示,完后最后的信息的输入,之后在屏幕的的下方进行显示 当点击第一个按钮的时候,在下方就会简单的出现你自己刚刚输入的相关信息 ...