Frogger
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 24 Accepted Submission(s) : 8
Problem 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.
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
Source
PKU
/**最短路的变形,第一只青蛙每一次要尽可能跳远一点,题目上这样说了**/
/**
一个池塘中分布着n块可供青蛙跳跃的石头,坐标分别为sto[i].x和sto[i].y,
给出Freddy和Fiona站的石头,问Freddy想借助这些石头,跳去Fiona那,它的每次跳跃距离至少是多少?
**/
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <vector>
#include <bitset>
#include <cstdio>
#include <string>
#include <numeric>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};//up down left right
bool inmap(int x,int y,int n,int m){if(x<1||x>n||y<1||y>m)return false;return true;}
int hashmap(int x,int y,int m){return (x-1)*m+y;}
inline int Abs(int x)
{
if(x<0)
x=-x;
return x;
}
#define eps 1e-8
#define inf 0x7fffffff
#define debug puts("BUG")
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#define maxn 2200
int N;
double dis[maxn][maxn];//邻接矩阵存储无向图中两点之间的距离
int via[maxn]; //是否进行过了松弛
int x[maxn],y[maxn];
double d[maxn]; //源点到各点的距离
void init()
{
memset(via,0,sizeof(via));
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
for(int i=1;i<N;i++)//单源最短路需要初始化,在求最短路时,需要将与源点直接相邻的点路径更新,这里不需要
d[i]=100000000;
}
double max(double a,double b)
{
if(a>b)
return a;
else
return b;
}
void Dijkstra()
{
d[0]=0;
via[0]=1;
int n=N-1;
int now=0;
while(n--)
{
int temp;
double mind=100000;
for(int i=1;i<N;i++)
{
if(!via[i])
{
if(d[i]>max(d[now],dis[i][now]))//不需要的原因就是要求的是最小的最大值
d[i]=max(d[now],dis[i][now]);
if(mind>d[i])
{
mind=d[i];
temp=i;
}
}
}
now=temp;
via[now]=1;
if(temp==1)
return ;
}
}
int main()
{
int icas=1;
while(~scanf("%d",&N)&&N)
{
init();
for(int i=0;i<N;i++)
scanf("%d%d",&x[i],&y[i]);
for(int j=0;j<N;j++)
for(int k=0;k<N;k++)
{
int a=Abs(x[j]-x[k]);
int b=Abs(y[j]-y[k]);
dis[j][k]=sqrt((double)(a*a+b*b));
}
Dijkstra();
printf("Scenario #%d\nFrog Distance = %.3lf\n\n",icas++,d[1]);
}
return 0;
}