https://vjudge.net/problem/POJ-2253

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
 //#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#define maxn 210
#define ms(x,n) memset(x,n,sizeof x);
const int inf=0x3f3f3f3f;
using namespace std;
int n;
double d[maxn],cost[maxn][maxn];
bool vis[maxn];
struct node
{
int x,y;
node(int xx,int yy){x=xx,y=yy;}
};
vector<node> v;
double dis(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
typedef pair<double,int> p; void dij(int s)
{
fill_n(d,maxn,inf);
ms(vis,);
priority_queue<p,vector<p>,greater<p> >q;
q.push(p(d[s]=,s));
while(!q.empty())
{
p cur=q.top();
q.pop();
int i=cur.second;
if(vis[i])continue;
vis[i]=;
for(int j=;j<n;j++)
{
if(max(d[i],cost[i][j])<d[j])
{d[j]=max(d[i],cost[i][j]);
q.push(p(d[j],j));
}
}
}
}
int main()
{
int t=;
while(~scanf("%d",&n),n)
{
int x,y;
v.clear();
for(int i=;i<=n;i++)
{
scanf("%d%d",&x,&y);
v.push_back(node(x,y));
}
fill_n(cost[],maxn*maxn,inf);
for(int i=;i<n;i++)
for(int j=i+;j<n;j++)
cost[i][j]=cost[j][i]=dis(v[i].x,v[i].y,v[j].x,v[j].y);
dij();
if(t)cout<<endl;
// printf("Scenario #%d\nFrog Distance = %.3f\n",t++,d[1]);
printf("Scenario #%d\nFrog Distance = %.3f\n", ++t, d[]); }
return ;
}

POJ2253(dijkstra堆优化)的更多相关文章

  1. POJ 2502 - Subway Dijkstra堆优化试水

    做这道题的动机就是想练习一下堆的应用,顺便补一下好久没看的图论算法. Dijkstra算法概述 //从0出发的单源最短路 dis[][] = {INF} ReadMap(dis); for i = 0 ...

  2. Bzoj 2834: 回家的路 dijkstra,堆优化,分层图,最短路

    2834: 回家的路 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 62  Solved: 38[Submit][Status][Discuss] D ...

  3. POJ2387(dijkstra堆优化)

    Til the Cows Come Home Bessie is out in the field and wants to get back to the barn to get as much s ...

  4. hdu 2544 单源最短路问题 dijkstra+堆优化模板

    最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  5. 深入理解dijkstra+堆优化

    深入理解dijkstra+堆优化 其实就这几种代码几种结构,记住了完全就可以举一反三,所以多记多练多优化多思考. Dijkstra   对于一个有向图或无向图,所有边权为正(边用邻接矩阵的形式给出), ...

  6. dijkstra堆优化(multiset实现->大大减小代码量)

    例题: Time Limit: 1 second Memory Limit: 128 MB [问题描述] 在电视时代,没有多少人观看戏剧表演.Malidinesia古董喜剧演员意识到这一事实,他们想宣 ...

  7. POJ 1511 - Invitation Cards 邻接表 Dijkstra堆优化

    昨天的题太水了,堆优化跑的不爽,今天换了一个题,1000000个点,1000000条边= = 试一试邻接表 写的过程中遇到了一些问题,由于习惯于把数据结构封装在 struct 里,结果 int [10 ...

  8. Dijkstra堆优化学习

    最短路径例题 今天特地学习了Dijkstra的堆优化(主要是慕名已久). 我们需要一个堆来记录[编号,到编号这个点的最短路径值(当然只是当前的)] 与原来的Dijkstra操作基本一致,主要有以下几点 ...

  9. 【Dijkstra堆优化】洛谷P2243电路维修

    题目背景 Elf 是来自Gliese 星球的少女,由于偶然的原因漂流到了地球上.在她无依无靠的时候,善良的运输队员Mark 和James 收留了她.Elf 很感谢Mark和James,可是一直也没能给 ...

随机推荐

  1. 【Java基础】9、Enumeration接口和Iterator接口的区别

    package java.util; public interface Enumeration<E> {     boolean hasMoreElements();     E next ...

  2. Clock Pictures(kmp + Contest2075 - 湖南多校对抗赛(2015.04.26))

    Problem H: Clock Pictures Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 73  Solved: 18[Submit][Stat ...

  3. 如何用minitab检测一组数据是否服从正态分布

    打开Minitab之后 点击Stat>Basic Statistics> Normality Test  分析之后若 P value(P值)>0.05,说明此组数据服从正态分布

  4. SQL Server 创建和修改数据表

    一.CREATE语句(创建) 1.创建DataBase 1.CONTAINMENT SQL Server 2012 新功能 , 默认值是OFF .(太高级 书上也没有详细介绍). 2.ON ON用于两 ...

  5. HTML--SVG基础

    一 SVG概述 SVG是Scalable Vector Graphics的缩写,即缩放式矢量图形; 优点: 1.使用编辑器即可编辑图形; 2.基于XML,SVG图形可以被很容易的搜索,脚本化和压缩; ...

  6. InheritParasitic.js

    // 寄生式继承 // 其基本思路是类似创建对象时的工厂模式,将继承过程封装在一个函数里,然后返回一个对象 function createObject(o){ var clone = Object.c ...

  7. ionic 一些常见问题和命令

    最近项目需要用到ionic就马上去撸,但是做下来发现官方文档的native插件,按照文档来做也遇到很多坑或者暂时想不出办法实现的. ionic这种属于跨平台的开发,是适用于比较常见通用的平台,安卓机, ...

  8. Apex的对象共享

    Apex的对象共享 在Apex中,每个对象都有一个"共享"对象,其中存储了该对象的共享设定. 这种共享对象以"share"结尾.比如Account的共享对象是A ...

  9. python 提取linux的硬件信息

    1.代码实现目的 注:代码可以直接粘贴使用 为了实现对主机的整体有明确的了解,实现了下面的代码功能 代码主要功能是: 提取到主机的内存.硬盘.CPU.型号等信息 插入到mysql的数据库中 2.代码具 ...

  10. Android Color颜色代码

    常用颜色代码 <?xml version="1.0" encoding="utf-8"?> <resources> <color ...