Frogger


Time Limit: 2 Seconds      Memory Limit: 65536 KB


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

就是说公青蛙和母青蛙都在一棵树上时,求当前树上的最大边;最小生成树,最后用并查集思想过。

附ac代码:

   #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int per[220000];
struct node
{
int start;
int end;
double dis;
}t[200100];
int cmp(node a,node b)
{
return a.dis < b.dis ;
}
int find(int x)
{
int r=x;
while(r!=per[r])
r=per[r];
return r;
}
int join(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx!=fy)
{
per[fx]=fy;
return 1;
}
return 0;
}
int main()
{
int i,n,j;
int flag=1;
double x[110000],y[110000];
while(scanf("%d",&n),n)
{
for(i=0;i<220000;i++)
per[i]=i;
for(i=1;i<=n;i++)
scanf("%lf%lf",&x[i],&y[i]);
int k=0;
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
{
t[k].start = i;
t[k].end = j;
t[k].dis =sqrt(((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))*1.0);
k++;
}
sort(t,t+k,cmp);
double ans=0.0;
int a=0;
int b=0;
for(i=0;i<k;i++)
{
if(join(t[i].start,t[i].end))
{
/*if(ans<t[i].dis)
ans=t[i].dis;
if(x[t[i].start]==x[1]&&y[t[i].end]==y[1])
a=1;
if(x[t[i].start]==x[1]&&y[t[i].end]==y[1])
b=1;
if(a==1&&b==1)*/
if(find(1)==find(2))//公青蛙和母青蛙,在同一颗树上,
{
ans=t[i].dis;//按顺序加的边,当前边一定是所成树的最大边
break;
}
}
}
printf("Scenario #%d\n",flag);
printf("Frog Distance = %.3f\n\n",ans);
flag++;
}
return 0;
}

zoj1942Frogger的更多相关文章

随机推荐

  1. java中多线程知识

    参考:http://www.cnblogs.com/wxd0108/p/5479442. 引 如果对什么是线程.什么是进程仍存有疑惑,请先Google之,因为这两个概念不在本文的范围之内. 用多线程只 ...

  2. SPOJ1812: LCS2 - Longest Common Substring II & BZOJ2946: [Poi2000]公共串

    [传送门:SPOJ1811&BZOJ2946] 简要题意: 给出若干个字符串,求出这些字符串的最长公共子串 题解: 后缀自动机 这两道题的区别只是在于一道给出了字符串个数,一个没给,不过也差不 ...

  3. 如何让alertdialog选择完后自动关闭

    builder.setIcon(R.drawable.ic_system) .setTitle("串口号") .setSingleChoiceItems(mPorts, mSele ...

  4. codeforces 404 B Marathon【fmod对浮点数取余】

    题意:给出一个边长为a的正方形,给出d,给出n,输出走得距离为i个d的时候的坐标 学习的这一篇 http://blog.csdn.net/synapse7/article/details/215956 ...

  5. ReactiveCocoa 中 RACSignal 所有变换操作底层实现分析(上)

    前言 在上篇文章中,详细分析了RACSignal是创建和订阅的详细过程.看到底层源码实现后,就能发现,ReactiveCocoa这个FRP的库,实现响应式(RP)是用Block闭包来实现的,而并不是用 ...

  6. <<大学>>原文

    大学之道,在明明德,在亲民,在止于至善.知止而后有定,定而后能静,静而后能安,安而后能虑,虑而后能得.物有本末,事有终始,知所先后,则近道矣. 古之欲明明德于天下者,先治其国,欲治其国者,先齐其家:欲 ...

  7. IDL build

    For Developers‎ > ‎Design Documents‎ > ‎ IDL build 目录 1 Steps 2 GYP 3 Performance 3.1 Details ...

  8. 紫书 习题 10-14 UVa 10886(暴力+数据范围)

    开始的时候一看这题感觉很难,觉得肯定有什么很快的办法 不能暴力做(受了上一题10-13的影响) 然后一看那个函数感觉无从下手. 然后看了博客发现,原来这道题就是直接暴力-- 因为n的范围为10的7次方 ...

  9. unity 自动删除未引用的Assets下的资源

    随着时间的堆积,项目中Assets文件夹下的资源会变得越来越繁杂,有些贴图.材质啥的可能压根没有使用过,但是又不敢轻易去删除. 这里分享两个插件,用于管理这些资源. 一.ResourceChecker ...

  10. POJ1158 城市交通Traffic lights IOI 1999 (最短路)

    POJ1158 城市交通Traffic lights IOI 1999 (最短路) (1) 问题描述(probolem) 在d城里交通的安排不同寻常,城中有路口和路口之间的道路,再任意两个不同的路口之 ...