zoj1942Frogger
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的更多相关文章
随机推荐
- Android 进程常驻(0)----MarsDaemon使用说明
版权声明:本文为博主原创文章,未经博主允许不得转载. 这是一个轻量级的库,配置几行代码,就可以实现在Android上实现进程常驻,也就是在系统强杀下,以及360获取root权限下,clean mast ...
- 为Activity生成桌面快捷方式
有时候如果想让我们的应用在桌面上创建多个快捷方式,我们可以在Manifest.xml文件中对相应的activity进行声明. <application android:icon="@d ...
- ubuntu配置上网
一.通过修改配置文件配置: 编辑配置文件: #sudo vim /etc/network/interfaces auto ens33 #没有这句网卡不能启动 iface ens33 i ...
- Tiles入门及项目实战
1.Apache Tiles™ Apache Tiles是一个模板布局框架.最初是为了简化Web应用界面开发,如今已不限于JavaEE Web环境. Tiles允许开发人员定义页面片段,它们在运行时会 ...
- ArchLinux 调节屏幕亮度和音量大小
我使用的是dwm,所以这种琐碎小事还要我们亲自动手, 以后考虑做个脚本,把声音调节.屏幕亮度什么的统统塞进去 屏幕亮度 # 查看亮度最大值 cat /sys/class/backlight/intel ...
- django 在非空的字段里插入现象表述
1.char 类型设置为非空 对于字段不赋值 默认储存为''(空字符串) 2.int 类型设置为非空 对于字段不赋值 单条插入 报错 多条数据同时插入 默认设置为0
- 题解 P3243 【[HNOI2015]菜肴制作】
这道题看起来就是个裸的拓扑排序,抄上模板就能AC. 上面这种想法一看就不现实,然鹅我第一次还真就这么写了,然后被随意hack. 我们需要注意一句话: 现在,酒店希望能求出一个最优的菜肴的制作顺序,使得 ...
- [Teamcenter 2007 开发实战] 调用web service
前言 在TC的服务端开发中, 能够使用gsoap 来调用web service. 怎样使用 gsoap , 參考 gsoap 实现 C/C++ 调用web service 接下来介绍怎样在TC中进行 ...
- centos7;windows下安装和使用spice
感谢朋友支持本博客,欢迎共同探讨交流,因为能力和时间有限,错误之处在所难免,欢迎指正! 假设转载,请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...
- hdu 3547 DIY Cube (Ploya定理)
DIY Cube Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total S ...