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

  1. 2
  2. 0 0
  3. 3 4
  4.  
  5. 3
  6. 17 4
  7. 19 4
  8. 18 5
  9.  
  10. 0

Sample Output

  1. Scenario #1
  2. Frog Distance = 5.000
  3.  
  4. Scenario #2
  5. Frog Distance = 1.414
  1. 题意:给出n个点的坐标,连通第一个点和第二个点有很多条路径,每条路径都会有 一个最大距离d - ->(当前路径经过的点集里面 任意两点间的距离都小于或者等于d)。题目要求找到这样的一个路径:(1)连通12两点;(2)这条路径中的最大距离d 是所有可选择路径中最小的。 输出这条路径的最大距离d
  2.  
  3. 题解:利用并查集kruskal算法;先将任意两个点之间的距离按从小到大的顺序排列,然后开始枚举所有的边,直至找到使起点和终点联通的边;
    因为要求所有可以连通的路径的最大权值中最小的,所以一旦找到使其连通的边就是所要求的结果
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<math.h>
  4. #include<algorithm>
  5. #define MAX 210
  6. #define DD double
  7. using namespace std;
  8. int set[MAX];
  9. DD a[MAX],b[MAX];
  10. int k,t,n;
  11. struct node
  12. {
  13. int u,v;
  14. DD w;
  15. }s[50000];
  16. bool cmp(node a,node b)
  17. {
  18. return a.w<b.w;
  19. }
  20. DD dis(DD x1,DD y1,DD x2,DD y2)
  21. {
  22. return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  23. }
  24. void init()
  25. {
  26. for(int i=0;i<=n;i++)
  27. set[i]=i;
  28. }
  29. void getmap()
  30. {
  31. for(int i=0;i<n;i++)
  32. scanf("%lf%lf",&a[i],&b[i]);
  33. k=0;
  34. for(int i=0;i<n-1;i++)
  35. for(int j=i+1;j<n;j++)
  36. {
  37. s[k].u=i;
  38. s[k].v=j;
  39. s[k++].w=dis(a[i],b[i],a[j],b[j]);
  40. }
  41. sort(s,s+k,cmp);
  42. }
  43. int find(int fa)
  44. {
  45. if(fa==set[fa])
  46. return fa;
  47. return set[fa]=find(set[fa]);
  48. }
  49. void mix(int x,int y)
  50. {
  51. int fx,fy;
  52. fx=find(x);
  53. fy=find(y);
  54. if(fx!=fy)
  55. set[fx]=fy;
  56. }
  57. void solve()
  58. {
  59. int i,j;
  60. int ok;
  61. DD ant;
  62. for(i=0;i<k;i++)
  63. {
  64. ok=0;
  65. ant=s[i].w;
  66. mix(s[i].u,s[i].v);
  67. if(find(0)==find(1))//判断是否连通
  68. ok=1;
  69. if(ok)//第一次连通时就是最小的
  70. {
  71. printf("Scenario #%d\n",++t);
  72. printf("Frog Distance = %.3f\n\n",ant);
  73. return ;
  74. }
  75. }
  76. }
  77. int main()
  78. {
  79. t=0;
  80. while(scanf("%d",&n),n)
  81. {
  82. init();
  83. getmap();
  84. solve();
  85. }
  86. return 0;
  87. }

  

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. 类库探源——System.Environment

    Environment 类: 提供有关当前环境和平台的信息以及操作它们的方法.此类不能被继承. 命名空间: System 程序集:   mscorlib.dll 继承关系: 常用属性(字段)和方法: ...

  2. 数据挖掘学习笔记:挖掘频繁模式、关联和相关[ZZ]

    所 谓挖掘频繁模式,关联和相关,即指在出现的数据集中找到一个经常出现的序列模式或者是一个经常出现的数据结构.就像搞CPU设计的人知道,Cache的预 取机制有流预取和指针预取,前者就是发现流模式,即发 ...

  3. VS2008中MFC界面编程Caption中文全是乱码的解决办法 -转载

    一.问题 在预览状态下可能看到中文,但是编译运行后对话框中的中文全是问号.即使你用的VS中文版,即使你也用了Unicode编码,即使有条件编译 #ifdef _WIN32LANGUAGE LANG_C ...

  4. TP缓存设计方案解析

    TP的缓存主要依赖Cache类,Cache类其实是一个代理类,Cache类通过getInstance静态方法来获取缓存实例,而getInstance方式实际是调用Cache类的connect方法,该方 ...

  5. 要想重启后也生效LINUX防火墙配置

    新配置的一台服务器,安装的是CentOS6.3系统,在安装完LNMP之后,发现nginx进程存在,且php解析正常,但是用分配的独立IP去访问的时候发现无法访问. 查了下网上的资料,发现可能是Linu ...

  6. ubuntu14.04 开启root登陆

    想要在登录界面使用root身份登录,可编辑/usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf文件, sudo gedit /usr/share/light ...

  7. [C#学习]在多线程中如何调用Winform[转]

    问题的产生: 我的WinForm程序中有一个用于更新主窗口的工作线程(worker thread),但文档中却提示我不能在多线程中调用这个form(为什么?),而事实上我在调用时程序常常会崩掉.请问如 ...

  8. php练习——打印半金字塔、金字塔、空心金字塔、菱形、空心菱形

    半金字塔 金字塔 空心金字塔 菱形     空心菱形

  9. ZendFramework使用中常见问题

    MVC 代码书写:控制器代码书写:<?phpclass IndexController extends Zend_Controller_Action{ function init() { $th ...

  10. Flex时间操作

    小弟是Flex新手,最近一段时间领导要求使用Flex开发B/S的一些项目,需要用到时间上的一些操作.上网查询一番好多人都说不好操作,有的甚至非常麻烦.基于此,小弟整理了一些关于Flex时间操作的经验, ...