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.
翻译:
弗雷迪·青蛙坐在湖中的一块石头上。突然,他发现菲奥娜·青蛙坐在另一块石头上。他计划去看望她,但由于水很脏,而且有很多游客的防晒霜,所以他想避免游泳,而是跳到她跟前。
不幸的是菲奥娜的石头超出了他的跳跃范围。因此,弗雷迪考虑使用其他石头作为中间停止,并通过几次小跳跃的顺序到达她。
要执行给定的跳跃序列,青蛙的跳跃范围显然必须至少与序列中发生的最长跳跃相同。
因此,两块石头之间的青蛙距离(人类也称之为最小-最大距离)被定义为两块石头之间所有可能路径的最小必要跳跃范围。
你得到了弗雷迪的石头,菲奥娜的石头和湖中所有其他石头的坐标。你的工作是计算弗雷迪和菲奥娜石头之间的青蛙距离。
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.
翻译:
输入将包含一个或多个测试用例。每个测试用例的第一行将包含石头数量n(2<=n<=200)。下n行各包含两个整数Xi,Yi(0<=Xi,Yi=1000),表示石头的坐标i。石头1是弗莱迪的石头,石头2是菲奥娜的石头,其他的N-2石头是空的。每个测试用例后面都有一个空白行。对于n,输入以零(0)的值终止。
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.
翻译:
对于每个测试用例,打印一行“Scenario_x”和一行“Frog Distance=y”,其中x替换为测试用例编号(从1开始编号),y替换为适当的实数,打印为三位小数。在每个测试用例之后,甚至在最后一个测试用例之后,都放一个空白行。
2
0 0
3 4
3
17 4
19 4
18 5
0
Scenario #1
Frog Distance = 5.000
Scenario #2
Frog Distance = 1.414
就是一个求最短路的题,要求选择的路线上跳跃的最大距离,小于其它任何路线上可以跳的最大距离。
输出选择的路线上可以跳的最大距离;
求青蛙a跳到青蛙b的石头上最短路
提交的时候记得 是 c++提交 否则会wa
如果坚持要用g++ 的话 要把%lf 改成 %f
代码如下:
//选择的路线上可以跳的最大距离,小于其它任何路线上可以跳的最大距离。
//输出两者间所有路径的最大值的最小值
#include
#include
#include
#include
using namespace std;
int i,j,k,s=0,n,m,temp,a=1;
int book[1111],e[1111][2]; //book 用来储存是否经过 e用来储存 石头的坐标
double dis[1111]; //储存距离
const int inf=99999999;
double space(int a,int b) //计算两点间的距离
{
double x=(e[a][0]-e[b][0])*1.0;
double y=(e[a][1]-e[b][1])*1.0;
return sqrt(x*x+y*y);
}
void dijk(int n)
{
memset(book,0,sizeof(book)); //初始化
for(i=0;i<=n;i++) //初始化
dis[i]=inf;
dis[1]=0; //最开始青蛙a在的那块石头跳的距离为0
for(j=1;j<=n;j++)
{
m=0;
temp=inf;
for(k=1;k<=n;k++) //距离青蛙a在的石头最近的那块石头
if(!book[k]&&dis[k]max(dis[m],space(m,k)))
dis[k]=max(dis[m],space(m,k));
}
}
int main()
{
while(~scanf("%d",&n) && n!=0) //输入 石头的个数
{
for(i=1;i<=n;i++)
{
scanf("%d%d",&e[i][0],&e[i][1]); //输入石头的坐标
}
dijk(n); //调用
s++;
printf("Scenario #%d\n",s); //输出第几个案例
printf("Frog Distance = %.3lf\n\n",dis[2]); //输出案例中所有路径的最大跳跃距离中的最小值
}
return 0;
}