题目连接: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. 关于HTML中的object元素

    <object>元素:它主要用于定义网页中的多媒体,比如音频,视频,Java applets,PDF,Active和Flash.object标签内除了param标签外,其他的内容将在浏览器 ...

  2. BZOJ4602 SDOI2016齿轮(搜索)

    dfs一遍给每个齿轮随便标个值看是否矛盾就行了. #include<iostream> #include<cstdio> #include<cmath> #incl ...

  3. WM_CTLCOLOR消息

    文章参考地址:http://blog.csdn.net/hisinwang/article/details/8070393         在每个控件开始绘制之前,都会向其父窗口发送WM_CTLCOL ...

  4. [Leetcode] Remove duplicate from sorted list ii 从已排序的链表中删除重复结点

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...

  5. BZOJ2818 GCD 【莫比乌斯反演】

    2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MB Submit: 6826 Solved: 3013 [Submit][Status][Discuss ...

  6. ubuntu下使用sudo 出现unable to resolve host 解决方法

    Linux 环境, 假设这台机器名字叫dev(机器的hostname), 每次执行sudo 就出现这个警告讯息:sudo: unable to resolve host dev虽然sudo 还是可以正 ...

  7. word公式编辑中的转义字符

    Some of the commonly used symbols:      \infty - Infinity      \leq - Less then or equal      \geq - ...

  8. 安卓recyclerview的基本使用

    1.先在布局文件中写 <android.support.v7.widget.RecyclerView android:id="@+id/my_recycler_view" a ...

  9. 线段树模板 CDOJ1057

    UESTCOJ不知道为什么进不去了哇 跟着叉姐的算法讲堂写的板子 叉姐的思路真的好清晰啊,一定是练习的多并且理解的够深了 希望自己也可以每天进步一点点吧 代码: #include <map> ...

  10. hadoop 架构