poj 2253 Frogger (最长路中的最短路)

链接:poj 2253

题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过任意石头到达B,

问从A到B多条路径中的最长边中的最短距离

分析:这题是最短路的变形,以前求的是路径总长的最小值,而此题是通路中最长边的最小值,每条边的权值可以通过坐标算出,因为是单源起点,直接用SPFA算法或dijkstra算法就可以了

SPFA 16MS

#include<cstdio>
#include<queue>
#include<cmath>
#include<climits>
using namespace std;
double a[205][205],dis[205];
int vis[205];
double max(double a,double b)
{
    return a>b?a:b;
}
void SPFA(int n)
{
    queue<int> q;
    int i,j;
    for(i=2;i<=n;i++){
        dis[i]=INT_MAX;
        vis[i]=0;
    }
    dis[1]=0;
    q.push(1);
    vis[1]=1;
    while(!q.empty()){
        i=q.front();
        q.pop();
        vis[i]=0;
        for(j=1;j<=n;j++)
            if(dis[j]>max(dis[i],a[i][j])){
                dis[j]=max(dis[i],a[i][j]);
                if(!vis[j]){
                    q.push(j);
                    vis[j]=1;
                }
            }
    }
}
int main()
{
    int i,j,n,k=0,x[205],y[205];
    while(scanf("%d",&n)!=EOF){
        if(n==0)
            break;
        k++;
        printf("Scenario #%d\n",k);
        for(i=1;i<=n;i++)
            scanf("%d%d",&x[i],&y[i]);
        for(i=1;i<=n;i++)
            for(j=1;j<=i;j++)
                a[i][j]=a[j][i]=sqrt(double(x[i]-x[j])*(x[i]-x[j])+double(y[i]-y[j])*(y[i]-y[j]));
        SPFA(n);
        printf("Frog Distance = %.3lf\n\n",dis[2]);
    }
    return 0;
}

poj 2253 Frogger (最长路中的最短路)

时间: 2024-08-10 02:10:59

poj 2253 Frogger (最长路中的最短路)的相关文章

poj 2253 Frogger 解题报告

题目链接:http://poj.org/problem?id=2253 题目意思:找出从Freddy's stone  到  Fiona's stone  最短路中的最长路. 很拗口是吧,举个例子.对于 i 到 j 的一条路径,如果有一个点k, i 到 k 的距离 && k 到 j 的距离都小于 i 到 j 的距离,那么就用这两条中较大的一条来更新 i 到 j 的距离 .每两点之间都这样求出路径.最后输出 1 到 2 的距离(1:Freddy's stone   2:Fiona's sto

Floyd-Warshall算法(求解任意两点间的最短路) 详解 + 变形 之 poj 2253 Frogger

/* 好久没有做有关图论的题了,复习一下. --------------------------------------------------------- 任意两点间的最短路(Floyd-Warshall算法) 动态规划: dp[k][i][j] := 节点i可以通过编号1,2...k的节点到达j节点的最短路径. 使用1,2...k的节点,可以分为以下两种情况来讨论: (1)i到j的最短路正好经过节点k一次 dp[k-1][i][k] + dp[k-1][k][j] (2)i到j的最短路完全

[2016-04-02][POJ][2253][Frogger]

时间:2016-04-02 17:55:33 星期六 题目编号:[2016-04-02][POJ][2253][Frogger] 题目大意:给定n个点的坐标,问从起点到终点的所有路径中,最大边的最小值是多少,即每一步至少是多少才能走到终点 分析: 方法1: 枚举出完全图,然后从起点跑一次Dijkstra算法,不过选点不再是选择起点到终点路径的点,而是起点到终点的路径中,边最大边最小的点,即d数组保存起点到当前点的路径中最大边的最小值, 最大边的最小值:u->v d[v] = min(d[i],m

poj 2253 Frogger (dijkstra最短路)

题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25773   Accepted: 8374 Description Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on an

POJ 2253 Frogger

题意:一只青蛙找到另外一只青蛙,不过可以通过其它的石头跳到目标青蛙的位置去,其中,输入数据的时候第一组数据是第一只青蛙的位置,第二组是目标青蛙的位置,其它的为石头的位置 思路:dijkstra算法的一种小小的变形,做法还是一样的 Tips:POJ上的双精度浮点型输出竟然是%f输出害的我一直错,或者是编译错误,恼啊! AC代码: #include<cstdio> #include<cmath> #include<algorithm> using namespace std

[ACM] POJ 2253 Frogger (最短路径变形,每条通路中的最长边的最小值)

Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24879   Accepted: 8076 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,

poj 2253 Frogger [dijkstra]

传送门:http://poj.org/problem?id=2253 Frogger 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

POJ 2253 - Frogger (floyd)

A - Frogger Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status 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

POJ 2253 Frogger(最小生成树)

题目链接:点击打开链接 题意:求从1到2的路径中, 使得最长路尽量小. 细节参见代码: #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> #include<vector> #include<stack> #include<bitset> #include<cstdlib>