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
题意:一只青蛙在X1,Y1的石头上,他要到X2,Y2的石头上续人,池塘上除了1、2两块石头外还有n-2块石头坐标分别为X3,Y3;X4,Y4……Xn,Yn
定义青蛙的跳跃范围为从石头一到石头二路径上所跳跃的最远距离,求跳跃范围的最小值
题解:spfa的判断稍微换一下就行了~
但要注意poj上.3f与.3lf的区别…….3f是不能用的
代码如下:
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std; vector< pair<int,double> > g[];
double d[],x[],y[];
int vis[],n; void spfa(int u)
{
memset(vis,,sizeof(vis));
for(int i=; i<=n; i++)
{
d[i]=inf;
}
d[u]=;
queue<int> q;
q.push(u);
while(!q.empty())
{
int x=q.front();
q.pop();
vis[x]=;
int sz=g[x].size();
for(int i=; i<sz; i++)
{
int y=g[x][i].first;
double w=g[x][i].second;
if(max(d[x],w)<d[y])
{
d[y]=max(d[x],w);
if(!vis[y])
{
q.push(y);
vis[y]=;
}
}
}
}
} int main()
{
int ttt=;
while(scanf("%d",&n),n)
{
ttt++;
for(int i=;i<=n;i++)
{
g[i].clear();
}
for(int i=; i<=n; i++)
{
scanf("%lf%lf",&x[i],&y[i]);
}
for(int i=; i<=n; i++)
{
for(int j=i+; j<=n; j++)
{
double dx=x[i]-x[j],dy=y[i]-y[j];
double dist=sqrt(dx*dx+dy*dy);
g[i].push_back(make_pair(j,dist));
g[j].push_back(make_pair(i,dist));
}
}
spfa();
printf("Scenario #%d\n",ttt);
printf("Frog Distance = %.3f\n",d[]);
printf("\n");
} }


最新文章

  1. 第三十三篇:使用uiresImporter生成uires.idx及skin.xml
  2. NPOI导入xls,xlsx格式实例
  3. linux服务器TCP并发连接数优化
  4. Ajax讲解
  5. Struts2总结
  6. 一些上流的CSS3图片样式
  7. 转:最简单的基于 DirectShow 的视频播放器
  8. java 项目打包流程速记
  9. 关于DISPLAY变量显示问题
  10. (C语言)char类型与int类型相加
  11. java输出换行的标准姿势&quot;line.separator&quot;
  12. IAR FOR ARM 各版本号,须要的大家能够收藏了
  13. 53. leetcode557. Reverse Words in a String III
  14. es6五种遍历对象属性的方法 - 表格整理
  15. java字符串以及字符类型基础
  16. STL迭代器iterator
  17. asp.net core mvc 在中间件中使用依赖注入问题:System.InvalidOperationException: Cannot resolve scoped service &#39;IXXXService&#39; from root provider.
  18. Python全栈之路----编程基本情况介绍
  19. linux网络设备—mdio总线
  20. Spark GraphX实例(3)

热门文章

  1. spring mvc静态资源访问的配置
  2. Maven引入jar包中的配置文件未被识别
  3. videojs集成--播放rtmp流
  4. 安装jenkins 的时候 记录默认密码文件为空的情况
  5. HDFS之五:Hadoop 拒绝远程 9000 端口访问
  6. Annotation之三:自定义注解示例,利用反射进行解析
  7. 1017 Queueing at Bank
  8. Unicode 和 UTF-8关系
  9. vue-cli脚手架build目录下utils.js工具配置文件详解
  10. leetcode872