题目连接: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. 【bzoj4152】[AMPPZ2014]The Captain 堆优化Dijkstra

    题目描述 给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1-y2|),求从1号点走到n号点的最小费用. 输入 第一行包含一个正整数n(2<=n< ...

  3. 详解npm的模块安装机制

    详解npm的模块安装机制 依赖树表面的逻辑结构与依赖树真实的物理结构 依赖树表面的逻辑结构与依赖树真实的物理结构并不一定相同! 这里要先提到两个命令:tree -d(linux)和npm ls(npm ...

  4. [Leetcode] Anagrams 颠倒字母构成词

    Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...

  5. CF451E Devu and Flowers 解题报告

    CF451E Devu and Flowers 题意: \(Devu\)有\(N\)个盒子,第\(i\)个盒子中有\(c_i\)枝花.同一个盒子内的花颜色相同,不同盒子的花颜色不同.\(Devu\)要 ...

  6. big 解题报告

    big 题目描述 你需要在\([0,2^n)\)中选一个整数\(x\),接着把\(x\)依次异或\(m\)个整数\(a_1\sim a_m\). 在你选出\(x\)后,你的对手需要选择恰好一个时刻(刚 ...

  7. 【2017.12.22.A】

                                A 题面: 给一个n个点m条边的无向图,你可以选择一个点作为起点,然后沿着图中的边开始走,走的过程中,同一条边不能经过两次(相反的方向也不行). ...

  8. 什么是node.js的事件驱动编程

    Node.js现在非常活跃,相关生态社区已经超过Lua(基本上比较知名的功能都有nodejs模块实现).但是我们为何要使用Node.Js?相比传统的webserver服务模式,nodejs有什么优点优 ...

  9. [HNOI2003]消防局的设立 (贪心)

    [HNOI2003]消防局的设立 题目描述 2020年,人类在火星上建立了一个庞大的基地群,总共有n个基地.起初为了节约材料,人类只修建了n-1条道路来连接这些基地,并且每两个基地都能够通过道路到达, ...

  10. 自定义toolbar教程

    1.写toolbar的布局文件 ,toolbar.xml <?xml version="1.0" encoding="utf-8"?> <Re ...