题目链接

http://poj.org/problem?id=2253

题意

给出青蛙A,B和若干石头的坐标,现在青蛙A要跳到青蛙B所在的石头上,求出所有路径中最远那一跳的最小值。

思路

Floyd算法的变形,将求两点之间的最短路改成求两点之间最大边权的最小值即可。

代码

 #include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std; const int N = ;
int x[N];
int y[N];
double dist[N][N];
int n; double get_dist(int i, int j)
{
return sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
} void floyd()
{
for(int k=; k<n; k++)
for(int i=;i<n; i++)
for(int j=; j<n; j++)
dist[i][j] = min(dist[i][j], max(dist[i][k], dist[k][j]));
} int main()
{
//freopen("poj2253.txt", "r", stdin);
int kase = ;
while(cin>>n && n)
{
memset(x, , sizeof(x));
memset(y, , sizeof(y)); for(int i=; i<n; i++)
cin>>x[i]>>y[i]; for(int i=; i<n; i++)
for(int j=; j<n; j++)
dist[i][j] = get_dist(i, j); floyd(); printf("Scenario #%d\n", kase++);
printf("Frog Distance = %.3f\n\n", dist[][]);
}
return ;
}

注意点

1、由于距离是double类型,输出的时候是可以用%.3lf的,但这题使用%.3lf会WA,要使用%.3f 来输出。

poj2253 Frogger(Floyd)的更多相关文章

  1. POJ2253——Frogger(Floyd变形)

    Frogger DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fi ...

  2. POJ2253 frogger 最短路 floyd

    #include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#inc ...

  3. POJ2253 Frogger

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34865   Accepted: 11192 Descrip ...

  4. POJ 2253 Frogger Floyd

    原题链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  5. poj2253(floyd变形)

    题目链接:https://vjudge.net/problem/POJ-2253 题意:给出n个点的坐标,求点1到点2的forg distance,其定义为点1到点2的所有路径中最长边的最小值. 思路 ...

  6. poj2253 Frogger(最短路变型或者最小生成树)

    /* 题意:就是源点到终点有多条的路径,每一条路径中都有一段最大的距离! 求这些路径中最大距离的最小值! Dijkstra, Floyd, spfa都是可以的!只不过是将松弛的条件变一下就行了! 想了 ...

  7. POJ 2253 Frogger floyd算法

    题目:click here 题意: 给出两只青蛙的坐标A.B,和其他的n-2个坐标,任意两坐标间是双向连通的.显然从A到B存在至少一条的通路,每一条通路的元素都是这条通路中前后两个点的距离,这些距离中 ...

  8. POJ-2253 Frogger(最短路)

    https://vjudge.net/problem/POJ-2253 题意 公青蛙想到母青蛙那里去,期间有许多石头,公青蛙可以通过这些石头跳过去.问至少要跳的最大距离,即所有路径上石头间的最大距离的 ...

  9. POJ2253 Frogger —— 最短路变形

    题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

随机推荐

  1. duilib 修复padding属性导致其他控件自动计算宽高度错误的bug和导致自己宽高度错误的bug

    转载请说明原出处,谢谢~~:http://blog.csdn.net/zhuhongshu/article/details/42950733          BUG 一:padding导致其他控件宽 ...

  2. HDU3068 最长回文 MANACHER+回文串

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3068 Problem Description 给出一个只由小写英文字符a,b,c...y,z组成的字符 ...

  3. Qt undefined reference to ***

    错因:某个类声明了一个函数但是没有定义就直接使用.

  4. Disruptor的使用

    ..................2015年的第一天................... 本文代码托管在 https://github.com/hupengcool/disruptor-start ...

  5. mysql数据库 批量替换 某字段中的数据

    当数据库出现这种情况: 表名:area id name 1  太仓 2  太仓市 3  太仓市 ... ... 我需要把 name字段中 的太仓市 的“市“去掉 可以使用: update `area` ...

  6. mysql 使用shell时出现 ERROR 2006 (HY000): MySQL server has gone away 解决方法

    ERROR (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection Current d ...

  7. mongoose使用简记

    mongodb中集合相当于表,常用指令 mongo 进入数据库 use yourdatabase 来选择你的数据集,这个跟关系型中的一样 show collections 来查看你数据集中的表,col ...

  8. 黑色的cms商城网站后台管理模板——后台

    链接:http://pan.baidu.com/s/1hst6Lbm 密码:9ad7

  9. ValueList用法

    ValueList的OverView 概述 在很多情况下,使用JDBC是很繁琐的,有很多方法可以替换JDBC,比如JDO.Hibernate等. 即使在从service中接收POJO的List的解决方 ...

  10. Python3 多进程

    多进程(multiprocessing)的用法和多线程(threading)类似,里面的函数也一样,start()为启动函数,join() 等待该进程运行结束,每一个进程也是由它的父进程产生 1.简单 ...