题目连接:http://poj.org/problem?id=2253

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.
题目大意:
青蛙A想到B那里去,他通过跳石头的方式过去,给出A,B所在位置和石头位置的坐标,要求得出所有路径中最大距离的最小值(A要到B可以选择不同路径,每条路径跳跃若干石头,每条路径都会有一个最大跳跃距离,即该路径中最远的两块石头的距离,要求求出这些路径中最大跳跃距离的最小值)
解题思路:
最短路径变形,原来求单源最短路径算法中dis数组用来储存起点到该节点距离,现在可以用来储存到达该点的路径中最大距离的最小值,相应的松弛操作也要修改。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>

#define MAX 205
#define INF 0x3ffffff
using namespace std;

int n;
double x[MAX];
double y[MAX];
double d[MAX];
bool vis[MAX];

void init(void)
{
    memset(vis,,sizeof(vis));
    ;i<n;i++)
        d[i]=INF;
}

void dijkstra(void)
{
    d[]=;
    ;i<n;i++)
    {
        int now,m=INF;
        ;j<n;j++)
        {
            if(!vis[j]&&d[j]<m)
            {
                now=j;
                m=d[j];
            }
        }
        vis[now]=;
        ;j<n;j++)
        {
            int xx=abs(x[now]-x[j]);
            int yy=abs(y[now]-y[j]);
            double dis=sqrt(pow(xx,2.0)+pow(yy,2.0));
            d[j]=min(d[j],max(d[now],dis));
        }
    }
}

int main()
{
    ;
    while(scanf("%d",&n)!=EOF)
    {
        )
            ;
        T++;
        ;i<n;i++)
            scanf("%lf%lf",&x[i],&y[i]);
        init();
        dijkstra();
        cout<<"Scenario #"<<T<<endl;
        cout<<"Frog Distance = ";
        printf(]);
        cout<<endl;
    }
}

思考:对于类似的题目,如果是能够在节点之间转移的属性,应该都可以通过类似的方法求出来。

poj2253 最短路变形的更多相关文章

  1. POJ-2253 Frogger---最短路变形&&最大边的最小值

    题目链接: https://vjudge.net/problem/POJ-2253 题目大意: 青蛙A想访问青蛙B,必须跳着石头过去,不幸的是,B所在的石头太远了,需要借助其他的石头,求从A到B的路径 ...

  2. POJ-2253(最短路变形+dijikstra算法+求解所有路径中所有最长边中的一个最小值)

    frogger POJ-2253 这题的代码特别像prim求解最小生成树的代码,其实两者本来也很像. 这里的d数组不再维护的起点到该点的最短距离了,而是路径中的最长距离. #include<io ...

  3. POJ-2253.Frogger.(求每条路径中最大值的最小值,最短路变形)

    做到了这个题,感觉网上的博客是真的水,只有kuangbin大神一句话就点醒了我,所以我写这篇博客是为了让最短路的入门者尽快脱坑...... 本题思路:本题是最短路的变形,要求出最短路中的最大跳跃距离, ...

  4. POJ 3635 - Full Tank? - [最短路变形][手写二叉堆优化Dijkstra][配对堆优化Dijkstra]

    题目链接:http://poj.org/problem?id=3635 题意题解等均参考:POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]. 一些口胡: ...

  5. POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]

    题目链接:http://poj.org/problem?id=3635 Description After going through the receipts from your car trip ...

  6. POJ-1797Heavy Transportation,最短路变形,用dijkstra稍加修改就可以了;

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K          Description Background  Hugo ...

  7. HDOJ find the safest road 1596【最短路变形】

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. HN0I2000最优乘车 (最短路变形)

    HN0I2000最优乘车 (最短路变形) 版权声明:本篇随笔版权归作者YJSheep(www.cnblogs.com/yangyaojia)所有,转载请保留原地址! [试题]为了简化城市公共汽车收费系 ...

  9. 天梯杯 PAT L2-001. 紧急救援 最短路变形

    作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图.在地图上显示有多个分散的城市和一些连接城市的快速道路.每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上.当其他城市有紧急求 ...

随机推荐

  1. JSP表单提交出现中文乱码的解决方法

    1)post方式 在servlet的doGet( )  doPost( )  中增加以下代码: response.setContentType("text/html;charset=utf- ...

  2. win7中输入文件夹首字母跳到相应的文件或者文件夹,却在搜索栏出现输入的字母

    组织->文件夹和搜索选项->查看->在视图中选择键入项

  3. [Leetcode] word break 拆分词语

    Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...

  4. springboot之mybatis别名的设置

    mybatis别名设置 在具体的mapper.xml文件中,定义很多的statement,statement需要parameterType指定输入参数的类型.需要resultType指定输出结果的映射 ...

  5. 测试数据库DG搭建为正式库以后做准备

    Data guard 部署 1.系统准备(备库只需建立数据库软件) 两台操作系统 oracle linux 7 Node1 172.16.70.191 Node2 172.16.70.192 Orac ...

  6. SQL性能分析

    MySQL常见瓶颈: CPU:CPU在饱和的时候一般发生在数据装入内存或从磁盘上读取数据的时候. IO:磁盘I/O瓶颈发生在装入数据远大于内存容量的时候. 服务器硬件的性能瓶颈:top.free.io ...

  7. javascript实现瀑布流效果(固定宽度)

    HTML代码: <div id="content"> <div class="box"> <div class="img ...

  8. MVC前台获取ViewData的数组中的值

    查了一上午资料,找到了一种比较有效的方法 后台控制器:public ActionResult Index() { List<string> colors = new List<str ...

  9. 动态规划:划分DP

    划分型动态规划之数的划分 先贴上2014年10月31日的那份代码,甚至怀念当时在机房YY这道题的场面 高中最快乐的时候.. #include<iostream> using namespa ...

  10. 之江学院第0届校赛 qwb去面试 (找规律)

    Description 某一天,qwb去WCfun面试,面试官问了他一个问题:把一个正整数n拆分成若干个正整数的和,请求出这些数乘积的最大值. qwb比较猥琐,借故上厕所偷偷上网求助,聪明的你能帮助他 ...