Frogger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 30427   Accepted: 9806

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
题意:给出n个点的坐标,连通第一个点和第二个点有很多条路径,每条路径都会有 一个最大距离d - ->(当前路径经过的点集里面 任意两点间的距离都小于或者等于d)。题目要求找到这样的一个路径:(1)连通1,2两点;(2)这条路径中的最大距离d 是所有可选择路径中最小的。  输出这条路径的最大距离d。

题解:利用并查集kruskal算法;先将任意两个点之间的距离按从小到大的顺序排列,然后开始枚举所有的边,直至找到使起点和终点联通的边;
因为要求所有可以连通的路径的最大权值中最小的,所以一旦找到使其连通的边就是所要求的结果
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define MAX 210
#define DD double
using namespace std;
int set[MAX];
DD a[MAX],b[MAX];
int k,t,n;
struct node
{
int u,v;
DD w;
}s[50000];
bool cmp(node a,node b)
{
return a.w<b.w;
}
DD dis(DD x1,DD y1,DD x2,DD y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
void init()
{
for(int i=0;i<=n;i++)
set[i]=i;
}
void getmap()
{
for(int i=0;i<n;i++)
scanf("%lf%lf",&a[i],&b[i]);
k=0;
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
{
s[k].u=i;
s[k].v=j;
s[k++].w=dis(a[i],b[i],a[j],b[j]);
}
sort(s,s+k,cmp);
}
int find(int fa)
{
if(fa==set[fa])
return fa;
return set[fa]=find(set[fa]);
}
void mix(int x,int y)
{
int fx,fy;
fx=find(x);
fy=find(y);
if(fx!=fy)
set[fx]=fy;
}
void solve()
{
int i,j;
int ok;
DD ant;
for(i=0;i<k;i++)
{
ok=0;
ant=s[i].w;
mix(s[i].u,s[i].v);
if(find(0)==find(1))//判断是否连通
ok=1;
if(ok)//第一次连通时就是最小的
{
printf("Scenario #%d\n",++t);
printf("Frog Distance = %.3f\n\n",ant);
return ;
}
}
}
int main()
{
t=0;
while(scanf("%d",&n),n)
{
init();
getmap();
solve();
}
return 0;
}

  

poj 2253 Frogger【最小生成树变形】【kruskal】的更多相关文章

  1. 最短路(Floyd_Warshall) POJ 2253 Frogger

    题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...

  2. POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)

    POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...

  3. POJ. 2253 Frogger (Dijkstra )

    POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...

  4. POJ 2253 Frogger(dijkstra 最短路

    POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...

  5. poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))

    传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  6. POJ 2253 Frogger ( 最短路变形 || 最小生成树 )

    题意 : 给出二维平面上 N 个点,前两个点为起点和终点,问你从起点到终点的所有路径中拥有最短两点间距是多少. 分析 : ① 考虑最小生成树中 Kruskal 算法,在建树的过程中贪心的从最小的边一个 ...

  7. POJ 2253 Frogger

    题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  8. poj 2253 Frogger (最长路中的最短路)

    链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...

  9. poj 2253 Frogger (dijkstra最短路)

    题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  10. POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】

    Frogger Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

随机推荐

  1. Linux下追踪函数调用,打印栈帧

    事情的起因是这样的,之前同事的代码有一个内存池出现了没有回收的情况.也就是是Pop出来的对象没有Push回去,情况很难复现,所以在Pop里的打印日志,跟踪是谁调用了它,我想在GDB调试里可以追踪调用的 ...

  2. 用3种方法在 operator= 中处理“自我赋值”

    假设你建立一个class 用来保存一个指针指向一块动态分配的位图. class Bitmap {......}; class Widget{ ... private: Bitmap* pb ; }; ...

  3. 忘记Mysql的root密码怎么办?

    解决方法: 1.打开cmd,用net start命令查看是否开启了mysql服务,如果开启,用net stop mysql 命令关闭mysql 2.进入mysql的安装目录下的bin目录,例如:E:\ ...

  4. 读书笔记之 - javascript 设计模式 - 接口、封装和链式调用

    javascript 采用设计模式主要有下面的三方面原因: 可维护性:设计模式有助于降低模块之间的耦合程度.这使代码进行重构和换用不同的模块变得容易,也使程序员在大型项目中合作变得容易. 沟通:设计模 ...

  5. javascript 获取 class 样式 重新赋值class样式 为div等系列标签内更改内容

    name = document.getElementById(project_not_through_id).className;                     // 获取目标id的 cla ...

  6. 《JavaScript高级程序设计 第3版》-学习笔记-2

    P31-P82页 1.相等不相等与全等不全等 相等不相等:先转换后比较.对于只有一个对象,调用valueOf方法得到基本类型值再按基本类型转换:如果两个都是对象,则比较他们是否是同一个对象(引用或指针 ...

  7. 移动端消除click事件的延迟效果

    https://github.com/Plaputta/jquery.event.special.fastclick 用fastclick事件,类似zepto的tap事件,若想去除连点效果,可在外层显 ...

  8. jquery 学习日记之选择器

    看完Jquery选择器的教程视频后,对jquery的选择器有一定的认识和了解,现整理一下知识: 一.jquery基本选择器,这类比较简单,一笔带过. #id 选择器,是选择  匹配id值中的第一个元素 ...

  9. JVM原理

    Java语言写的源程序通过Java编译器,编译成与平台无关的‘字节码程序’(.class文件,也就是0,1二进制程序),然后在OS之上的Java解释器中解释执行,而JVM是java的核心和基础,在ja ...

  10. 将图片文件转换为.py文件

    最近用wxpython写了一个脚本,其中要给窗体设置图标文件,需要单独的一个ico文件,这样就比较影响美观,另外打包的时候还要将图标文件一起打包很繁琐.这时候看到wxpython文件有一个工具img2 ...