B - Frogger(spfa)

题目链接:https://vjudge.net/contest/66569#problem/B

题目:

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 43
17 4
19 4
18 50

Sample Output

Scenario #1
Frog Distance = 5.000Scenario #2
Frog Distance = 1.414
题意:有两只青蛙和若干块石头,现在已知这些东西的坐标,两只青蛙A坐标和青蛙B坐标是第一个和第二个坐标,现在A青蛙想要到B青蛙那里去,并且A青蛙可以借助任意石头的跳跃,而从A到B有若干通路,问从A到B的所有通路上的最大边,比如有  有两条通路  1(4)5 (3)2 代表1到5之间的边为4,  5到2之间的边为3,那么该条通路跳跃范围(两块石头之间的最大距离)为 4,  另一条通路 1(6) 4(1) 2 ,该条通路的跳跃范围为6, 两条通路的跳跃范围分别是 4 ,6,我们要求的就是最小的那一个跳跃范围,即4,用三种方法都能解决思路:最短路模板题,稍微变化一下,就是每条路径选取最大的,选取这几条路径中最小的,即把模板中d[i]>d[now]+lu[now][i]改成d[i]>max(d[now],lu[now][i])就行了,WA了很多遍由于初始化的原因,spfa算法代码如下:

//
// Created by hanyu on 2019/7/14.
//
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<cstring>
#include<cstdio>
#include<math.h>
using namespace std;
typedef long long ll;
#define MAX 0x3f3f3f3f
const int maxn=1005;
double d[maxn];
double lu[maxn][maxn];
bool book[maxn];
int n;
void spfa(int a)
{for(int i=2;i<=n;i++){d[i]=MAX;book[i]=false;}//memset(book,false,sizeof(book))//memset(d,MAX,sizeof(d))//还是别用以上注释用的memset初始化,就因为这个WA了很多遍,找了两个小时的错误,不晓得为啥queue<int>qu;d[a]=false;book[a]=true;qu.push(a);int now;while(!qu.empty()){now=qu.front();qu.pop();book[now]=false;for(int i=1;i<=n;i++){if(d[i]>max(d[now],lu[now][i])){d[i]=max(d[now],lu[now][i]);if(!book[i]){qu.push(i);book[i]=true;}}}}
}
int main()
{int k=0;int a[maxn],b[maxn];while(~scanf("%d",&n)) {if (n == 0)break;for (int i = 1; i <= n; i++) {scanf("%d%d", &a[i], &b[i]);}for (int i = 1; i <= n; i++){for (int j = 1; j <= i; j++) {lu[i][j] = lu[j][i] = sqrt(double(a[i] - a[j]) * (a[i] - a[j]) +double(b[i] - b[j]) * (b[i] - b[j]));}}spfa(1);k++;printf("Scenario #%d\n",k);printf("Frog Distance = %.3lf\n\n",d[2]);}return 0;
}

转载于:https://www.cnblogs.com/Vampire6/p/11202573.html

[kuangbin带你飞]专题四 最短路练习 B( POJ 2253) Frogger(spfa)相关推荐

  1. [kuangbin带你飞]专题四 最短路练习 R

    http://acm.hdu.edu.cn/showproblem.php?pid=4370 HDU 4370 0 or 1(最短路) 这是整套里面我觉得最有意思的一道最短路,也确实让我觉得我与真正a ...

  2. [kuangbin带你飞]专题四 做题顺序与题解 【最短路练习】

    随便说点: 博主正在刷kuangbin专题的题目,初学者,没接触过什么算法,刷题的初衷是备战蓝桥杯,后来发现了算法资料大多是针对acm的,挑选kuangbin专题入门也是如此,毕竟这样分类看起来能达到 ...

  3. [kuangbin带你飞]专题一 简单搜索D - Fliptile(POJ 3279)

    题目大意 给一个N行M列的矩阵,值分别为0和1,每次你可以选择将一个变成相反状态,同时,它周围的四个数也会变为相反状态. 问:最少翻转多少次,可以将所有值都变成0 多个解,输出翻转次数最少的(若有次数 ...

  4. kuangbin带你飞专题合集

    题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...

  5. “kuangbin带你飞”专题计划——专题十四:数论基础

    写在前面 1.目前还没啥写的.开始时间:2021-05-13(其实博客上看得到该博客创建时间的) 2.上一个专题刷的是网络流(博客总结),属于第一次接触.本来想的是一周特别高效,然后一周略划水,结果是 ...

  6. (2021-07-14~)“kuangbin带你飞”专题计划——专题十三:基础计算几何

    目录 前言 参考博客 自己总结的东西: 难度判断? 题目 1.[TOYS POJ - 2318 ](解决) 2.[Toy Storage POJ - 2398 ](解决) 3.[Segments PO ...

  7. kuangbin带你飞 专题1-23 题单

    kuangbin大神,对于打过ACM比赛的ACMer,无人不知无人不晓. 在此,附上vjudge平台上一位大神整理的[kuangbin带你飞]专题目录链接. [kuangbin带你飞专题目录1-23] ...

  8. [kuangbin带你飞]专题十二 基础DP1 题解+总结

    kuangbin带你飞:点击进入新世界 总结: 简单dp,最近在做,持续更新. 文章目录 总结: 1.Max Sum Plus Plus 2.Ignatius and the Princess IV ...

  9. [kuangbin带你飞]专题五 并查集 题解+总结

    kuangbin带你飞:点击进入新世界 总结: 本人算是初学者中的初学者,欢迎交流~ 并查集的接触过的不多,大概只有普通并查集,带权并查集,种族并查集,传说中的可持续化并查集只是听说过还没有接触,不过 ...

最新文章

  1. fpm制作mysql rpm包_fpm制做mysql-5.6.33 rpm包
  2. MySQL bin-log 日志清理方式
  3. Linux调度系统全景指南(下篇)
  4. 中科大量子计算机科学家,中国科学院量子信息重点实验室
  5. 启动FastDFS服务,使用python客户端对接fastdfs完成上传测试
  6. 从工具到平台|默安科技研发安全一体化管理平台正式发布
  7. python字典{:4}_升级您的Python技能:检查字典
  8. mysql数据库文件上传大小控制_[mysql数据库文件大小限制]mysql导入数据库文件最大限制设置...
  9. 机器学习回归问题解答
  10. android常见的面试题,Android常见笔试面试题
  11. Swift入门基础知识
  12. MySQL最好的写的_mysql中写sql的好习惯
  13. iOS-PingFangSC字体
  14. MCU中RS485接口设计
  15. 怎么用wps做区域分布图_WPS表格如何进行多区域单元格的选择? 详情介绍
  16. 绘制一幅蓝图_给未来画一幅蓝图
  17. 打开WORD文档出错提示
  18. mysql delete in死锁_delete where in导致的死锁问题
  19. Android实现制作氢壁纸,氢壁纸怎么制作?氢壁纸制作方法介绍[图]
  20. 高等数学极限运算法则

热门文章

  1. HTTP 错误 404.15 - Not Found请求筛选模块被配置为拒绝包含的查询字符串过长的请求...
  2. MySql优化的方法
  3. 自定义控件之onMeasure
  4. HDU 4023 (博弈 贪心 模拟) Game
  5. 我的第一篇博客,以此写写内心的独白
  6. Android ListView 横向滑动删除 Item
  7. 如果修改了表结构的话,可能也需要将调用到表的存储过程、函数等也修改一下,以下语句可以查询到那些对象调用到被修改的表...
  8. oracle12c不能进入到http://localhost:1158/em的解决办法
  9. Linux - 网络相关指令
  10. 在网页中插入时间 自动更新