POJ 2253 Frogger

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. #include<iostream>
  2. #include<cmath>
  3. #include<cstdio>
  4. #define inf 10000000
  5. using namespace std;
  6. struct ac{
  7. int x,y;
  8. }a[];
  9. double temp[][],dis[];
  10. void dijkstra(int n){
  11. double minn;
  12. int flag,vis[]={};
  13. for(int i = ;i < n;++i)dis[i]=temp[][i];
  14. for(int i = ;i < n-;++i){
  15. minn=inf;flag=;
  16. for(int j = ;j < n;++j){
  17. if(minn>dis[j]&&!vis[j])minn=dis[j],flag=j;
  18. }
  19. vis[flag]=;
  20. for(int j = ;j < n;++j){
  21. dis[j]=min(dis[j],max(dis[flag],temp[flag][j]));
  22. }
  23. }
  24. }
  25. int main()
  26. {
  27. int m,ans=;
  28. while(cin>>m&&m){
  29. for(int i = ;i < m;++i)cin>>a[i].x>>a[i].y;
  30. // ac tempp=a[m-1];a[m-1]=a[1],a[1]=tempp;
  31. for(int i = ;i < m;++i){
  32. for(int j = ;j < m;++j){
  33. temp[i][j]=temp[j][i]=sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));
  34. }
  35. }
  36. dijkstra(m);
  37. if(ans!=)cout<<endl;
  38. printf("Scenario #%d\nFrog Distance = %.3f\n",ans++,dis[]);
  39. }
  40. }

AC代码

没想到最后是被输出格式卡了。。晕。。

POJ 2253 Frogger(dijkstra 最短路的更多相关文章

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

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

  2. POJ - 2253 Frogger(最短路Dijkstra or flod)

    题意:要从起点的石头跳到终点的石头,设The frog distance为从起点到终点的某一路径中两点间距离的最大值,问在从起点到终点的所有路径中The frog distance的最小值为多少. 分 ...

  3. POJ 2253 - Frogger - [dijkstra求最短路]

    Time Limit: 1000MS Memory Limit: 65536K Description Freddy Frog is sitting on a stone in the middle ...

  4. POJ 2253 Frogger【最短路变形——路径上最小的最大权】

    链接: http://poj.org/problem?id=2253 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  5. poj 2253 Frogger dijkstra算法实现

    点击打开链接 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21653   Accepted: 7042 D ...

  6. poj 2253 Frogger (最短路变种,连通图的最长边)

    题目 这里的dijsktra的变种代码是我看着自己打的,终于把代码和做法思路联系上了,也就是理解了算法——看来手跟着画一遍真的有助于理解. #define _CRT_SECURE_NO_WARNING ...

  7. POJ 2253 Frogger【最短路变形/最小生成树的最大权/最小瓶颈树/A到B多条路径中的最小的最长边】

    Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sit ...

  8. POJ 2253 Frogger(最短路&Floyd)题解

    题意:想给你公青蛙位置,再给你母青蛙位置,然后给你剩余位置,问你怎么走,公青蛙全力跳的的最远距离最小. 思路:这里不是求最短路径,而是要你找一条路,青蛙走这条路时,对他跳远要求最低.这个思想还是挺好迁 ...

  9. POJ. 2253 Frogger (Dijkstra )

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

随机推荐

  1. QT:设置布局边缘

    QHBoxLayout * horizontalLayout = new QHBoxLayout; //setContentsMargins(int left, int top, int right, ...

  2. codevs 1231 最优布线问题 x(find函数要从娃娃抓起系列)

                         题目描述 Description 学校需要将n台计算机连接起来,不同的2台计算机之间的连接费用可能是不同的.为了节省费用,我们考虑采用间接数据传输结束,就是一 ...

  3. HGOI20190811 省常中互测4

    Problem A magic 给出一个字符串$S$,和数字$n$,要求构造长度为$n$只含有小写字母的字符串$T$, 使得在$T$中存在删除且仅删除一个子串使得$S=T$成立. 输出$T$的构造方案 ...

  4. Kaggle 网站上的练习

    快速的数据科学教程: https://www.kaggle.com/learn/overview

  5. CentOS 7,使用yum安装Nginx

    https://www.centos.bz/2018/01/centos-7%EF%BC%8C%E4%BD%BF%E7%94%A8yum%E5%AE%89%E8%A3%85nginx/ 文章目录 [隐 ...

  6. MYSQL中唯一约束和唯一索引的区别

    1.唯一约束和唯一索引,都可以实现列数据的唯一,列值可以有null.2.创建唯一约束,会自动创建一个同名的唯一索引,该索引不能单独删除,删除约束会自动删除索引.唯一约束是通过唯一索引来实现数据的唯一. ...

  7. echarts+json笔记

    echart_test.html <!DOCTYPE html> <head> <meta charset="utf-8"> <scrip ...

  8. centos6 升级php版本

    配置yum源 追加CentOS 6.8的epel及remi源. # rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel- ...

  9. java面试要点

    基础篇 基本功 面向对象的特征 final, finally, finalize 的区别 int 和 Integer 有什么区别 重载和重写的区别 抽象类和接口有什么区别 说说反射的用途及实现 说说自 ...

  10. [Java]将算术表达式(中序表达式Infix)转成后续表达式Postfix

    Inlet类: package com.hy; import java.io.BufferedReader; import java.io.IOException; import java.io.In ...