Frogger

Frogger

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 (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


译:

[Description] 
Freddy青蛙坐在河中的一个石头上,突然他注意到了坐在另一个石头上的Fiona青蛙。他想接近她,但是湖中太脏了,充满了游人丢的垃圾,所以他想跳过去。 
不幸的是Fiona坐的石头不在他的跳跃范围内,所以Freddy想用其他的石头作为中转,通过一系列的小跳跃来接近Fiona。为了执行这一个序列的跳跃,一个青蛙的跳跃大小是在一条路径中的最大跳跃距离。如一条路径1->2->3->4中每次跳跃的长度为2, 5, 3,那么青蛙的跳跃大小就至少为5。frog distance(人们也把它叫做“极小极大距离”)的定义是在两个石头间所有的可行路径中的所需最小跳跃大小。现告诉你湖中的n个石头,Freddy在第1个石头,Fiona在第2个石头。

你需要计算出在Freddy和Fiona的石头间的frog distance

[Input]
多组数据,对于每组数据,第一行一个整数n,表示石头的个数。当n=0时输入结束
接下来n行,每行两个整数xi和yi,表示第i 个石头的坐标
[Output]
对于每组数据输出两行
第一行:Scenario #x      (x为第x组数据,# 前有一个空格)
第二行:Frog Distance = y    (y为所求答案,  = 前后均有空格)
[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


[Hint]
2 <= n <= 200, 0 <= xi, yi <= 1000


题意是“湖中有n个石头,一只青蛙要从1号石头上跳到2号石头上,求出跳过的石子的的路径中两个石子最大距离的最小值。

这道题很水:

spfa的变形,标准spfa是求i点到其他的最短路,通过dis[v]>dis[u]+w[u][v]进行松弛操作,这里我们要求的能走的路中最大边的最小值,则通过dis[v]>retret表示走过的边中最小的最大边)来进行松弛

②可以用 Folyd

Kruskal

附代码吧:

spfa:

#include
#include
#include
#include
#include
#include
using namespace std;
int n;
int x[210],y[210];
double frog[210];//储存当前最小frog distance
queue < int > q;

double dis(int a,int b)
{
	double k=0.0;
	k+=(x[a]-x[b])*(x[a]-x[b]);
	k+=(y[a]-y[b])*(y[a]-y[b]);
	k=sqrt(k);
	return k;
}

void spfa()
{
	int u;
	double v;
	while(!q.empty())
	{
		u=q.front();
		q.pop();
		for(int i=1;i<=n;i++)
		{
			if(i==u) continue;
			v=max(dis(i,u),frog[u]);
			if(v


Folyd:

#include
#include
#include 
#include 
using namespace std;
int n;
double b[201][201];
int v[201][2];
int cnt=0;
int main()
{
	while(scanf("%d",&n))
	{
		cnt++;
		if(n==0)break;
		for(int i=1;i<=n;i++)
			scanf("%d %d",&v[i][0],&v[i][1]);
		memset(b,0,sizeof(b));
		for(int i=1;i<=n;i++)
			for(int j=i+1;j<=n;j++)
				b[j][i]=b[i][j]=sqrt((double)(v[i][0]-v[j][0])*(v[i][0]-v[j][0])+(v[i][1]-v[j][1])*(v[i][1]-v[j][1]));
		for(int k=1;k<=n;k++)
			for(int i=1;i<=n;i++)
				for(int j=1;j<=n;j++)
					b[i][j]=min(max(b[i][k],b[k][j]),b[i][j]) ;
		printf("Scenario #%d\nFrog Distance = %.3lf\n\n",cnt,b[1][2]);
	}
    return 0;
}


kruskal:

#include
#include
#include
#include
#include
using namespace std;

int n,k=0,cnt=0;
int hash[210][210];
double map[210][210];
double f[210];
double ans;

struct node
{
	int u,v;
	double w;
}e[200000],z;

struct code
{
	int x,y;
}poi[210],zero;

double jsdis(code a,code b)
{
	double res=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
	return res;
}

void clear()
{
    ans=-1;
	for(int i=1;i<=n;i++) 
	{
		poi[i]=zero;
		f[i]=i;
	}
	for(int i=1;i<=n*n/2;i++) e[i]=z;
	memset(map,0,sizeof(map));
	memset(hash,0,sizeof(hash));
}

void adde(int u,int v)
{
	e[++k].u=u;
	e[k].v=v;
	e[k].w=jsdis(poi[u],poi[v]);
}

bool cmp(node a,node b)
{
	return a.w



你可能感兴趣的:(停课集训,并查集,最短路,图论)