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
一个青蛙从一个石头跳到目标石头,定义一条路的难度是这中间跳跃的最大距离,要求的是这些路线中,最大距离最小的那个。
其实就是把最短路比较中
d[v] = min(d[v],d[u] + w)改成d[v] = min(d[v],max(d[u],w));
#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
int head[202],leap[202];
double d[202];
struct Node
{
int x,y;
}node[202];
struct Edge
{
int u,v,next;
double w;
}edge[80005];
double dis(int a,int b)
{
return sqrt(1.0*(node[a].x - node[b].x)*(node[a].x - node[b].x) + (node[a].y - node[b].y)*(node[a].y - node[b].y));
}
void add_edge(int u,int v,double w,int tot)
{
edge[tot].u = u;edge[tot].v = v;
edge[tot].w = w;
edge[tot].next = head[u];
head[u] = tot;
}
int main()
{
#ifdef LOCAL
freopen("C:\\Users\\巍巍\\Desktop\\in.txt","r",stdin);
//freopen("C:\\Users\\巍巍\\Desktop\\out.txt","w",stdout);
#endif // LOCAL
int n,kase = 1;
while(scanf("%d",&n) != EOF)
{
if(n == 0)break;
for(int i = 1;i <= n;i++)
scanf("%d%d",&node[i].x,&node[i].y);
for(int i = 1;i <= n;i++)head[i] = -1;
int tot = 1;
for(int i = 1;i < n;i++)
{
for(int j = i + 1;j <= n;j++)
{
double d = dis(i,j);
add_edge(i,j,d,tot++);
add_edge(j,i,d,tot++);
}
}
for(int i = 1;i <= n;i++)d[i] = inf;
for(int i = 1;i <= n;i++)leap[i] = 0;
queue<int>p;
p.push(1);
leap[1] = 1;d[1] = 0;
while(p.size())
{
int u = p.front();p.pop();
leap[u] = 0;
for(int i = head[u];i != -1;i = edge[i].next)
{
int e = edge[i].v;
double temp = max(edge[i].w,d[u]);
if(d[e] > temp)
{
d[e] = temp;
if(!leap[e])
{
leap[e] = 1;
p.push(e);
}
}
}
}
printf("Scenario #%d\n",kase++);
printf("Frog Distance = %.3lf\n\n",d[2]);
}
return 0;
}
在一片湖中,Freddy 跳跃式地寻找他的朋友 Fiona,面临水脏且充满游客防晒霜的挑战。他考虑使用其他石头作为中转站,通过一系列小跳跃来达到目的地。每条路径的难度定义为最长跳跃的距离,任务是计算出从 Freddy 的石头到 Fiona 的石头之间的最小必要跳跃范围,即青蛙距离。
1万+

被折叠的 条评论
为什么被折叠?



