题目连接: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. hdu 1286 找新朋友 (欧拉函数)

    找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  2. [洛谷P1407][国家集训队]稳定婚姻

    题目大意:有$n$对夫妻和$m$对情人,如果一对情人中的两人都离婚了,那么他们可以结为夫妻.对于每一对夫妻,若他们离婚后所有人依然可以结婚,那么就是不安全的,否则是安全的.问每一对夫妻是否安全. 题解 ...

  3. CF451E Devu and Flowers 解题报告

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

  4. WCF分布式开发步步为赢(13):WCF服务离线操作与消息队列MSMQ

    之前曾经写过一个关于MSMQ消息队列的文章:WCF分布式开发必备知识(1):MSMQ消息队列 ,当时的目的也是用它来作为学习WCF 消息队列MSMQ编程的基础文章.在那篇文章里,我们详细介绍了MSMQ ...

  5. 怎么把centos虚拟机zip文件导入vm虚拟机中

    执行以上三步就可以将一个压缩的centoszip文件导入到虚拟机中

  6. 清理/var/spool/clientmqueue目录释放大量空间

    清理/var/spool/clientmqueue目录可以释放大量空间,具体命令是:ls | xargs rm -f 文件太大,rm -rf会由于参数太多而无法删除,所以需要用上面的命令. “Argu ...

  7. c#中数据库字符串的连接几种方式

    ADO.net 中数据库连接方式(微软提供) 微软提供了以下四种数据库连接方式:System.Data.OleDb.OleDbConnectionSystem.Data.SqlClient.SqlCo ...

  8. Java节假日算法

    类:Vacation package test; import java.io.Serializable; import java.util.Date; public class Vacation i ...

  9. 河南省第十届省赛 Intelligent Parking Building

    title: Intelligent Parking Building 河南省第十届省赛 tags: [模拟,省赛] 题目描述: There is a new revolution in the pa ...

  10. 滑杆(JSlider)和进度指示条(JProgressBar) 的使用

    package first; import javax.swing.*; import javax.swing.border.TitledBorder; import java.awt.*; impo ...