poj2253(floyd变形)
题目链接:https://vjudge.net/problem/POJ-2253
题意:给出n个点的坐标,求点1到点2的forg distance,其定义为点1到点2的所有路径中最长边的最小值。
思路:floyd真的很强大,改一下定义,dis[i][j]表示i到j的frog distance,然后枚举中间点k,转移方程是dis[i][j]=min(dis[i][j],max(dis[i][k],dis[k][j]))。复杂度O(n^3).
AC代码:
e<cstdio>
#include<cmath>
#include<algorithm>
using namespace std; typedef pair<int,int> PII;
const int maxn=;
PII p[maxn];
int n,cas;
double dis[maxn][maxn]; double getdis(PII p1,PII p2){
return sqrt((p1.first-p2.first)*(p1.first-p2.first)*1.0+
(p1.second-p2.second)*(p1.second-p2.second)*1.0);
} int main(){
while(scanf("%d",&n),n){
for(int i=;i<=n;++i){
int x,y;
scanf("%d%d",&x,&y);
p[i]=make_pair(x,y);
}
for(int i=;i<=n;++i){
dis[i][i]=0.0;
for(int j=i+;j<=n;++j)
dis[i][j]=dis[j][i]=getdis(p[i],p[j]);
}
for(int k=;k<=n;++k)
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
dis[i][j]=min(dis[i][j],max(dis[i][k],dis[k][j]));
printf("Scenario #%d\n",++cas);
printf("Frog Distance = %.3f\n\n",dis[][]);
}
return ;
}
poj2253(floyd变形)的更多相关文章
- POJ2253——Frogger(Floyd变形)
Frogger DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fi ...
- UVA10048 Audiophobia[Floyd变形]
UVA - 10048 Audiophobia Consider yourself lucky! Consider yourself lucky to be still breathing and h ...
- hdu 1596(Floyd 变形)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...
- hdu 1217 (Floyd变形)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others) ...
- Frogger(floyd变形)
Frogger Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- UVa 10048 (Floyd变形) Audiophobia
题意: 给一个带权无向图,和一些询问,每次询问两个点之间最大权的最小路径. 分析: 紫书上的题解是错误的,应该是把原算法中的加号变成max即可.但推理过程还是类似的,如果理解了Floyd算法的话,这个 ...
- find the mincost route(floyd变形 无向图最小环)
Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- hdu1569find the safest road(floyd变形求最大安全值)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- zoj3710 friends(floyd变形)
Friends Time Limit: 2 Seconds Memory Limit: 65536 KB Alice lives in the country where people li ...
随机推荐
- Maven+Docker 部署
Maven+Docker 部署 安装jdk8镜像 docker pull openjdk:8-jdk-alpine maven插件推送方式 修改/etc/docker/daemon.json文件,加入 ...
- Mongodb账户管理
Mongodb账户管理 介绍 Mongodb是一个schema free的非sql类分布式数据库,可以利用它做很多很灵活的存储和操作,最近了解了下它的账户机制,通过设置auth启动方式可以对所有登 ...
- fckeditor实现ctrl+v粘贴word图片并上传
tinymce是很优秀的一款富文本编辑器,可以去官网下载.https://www.tiny.cloud 这里分享的是它官网的一个收费插件powerpaste的旧版本源码,但也不影响功能使用. http ...
- easyui复选框实现单选框
$(':checkbox[name=primary_key_flag]').each(function(){ $(this).click(function(){ if(this.checked){ $ ...
- MyBatis入门使用
MyBatis入门使用 MyBatis简介 MyBatis是支持普通SQL查询.存储过程和高级映射的持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索.MyBati ...
- Springboot使用zuul进行负载均衡
完整项目代码地址参考:https://github.com/SimonHu1993/SpringbootZuul 1.这里我们使用Eureka来作为服务的注册与发现中心,首先看看Eureka clie ...
- Flutter路由跳转父级页面向子页面传参及子页面向父级页面传参
Flutter中页面通过路由跳转传参主要分两种,一种是通过push()跳转时根据设定的参数进行传参,另一种是通过pop()返回时进行传参. 父级页面向子页面push()传参 假设从A页面跳到B页面可能 ...
- dubbo 初识(1)
参考dubbo 中文官方文档:http://dubbo.apache.org/zh-cn/docs/user/preface/architecture.html 分布式架构的发展过程 1.初始小型的项 ...
- Razor字符串处理
需要注意的是低版本是不支持C# 6语法中的string interpolation的 <label> @if (!string.IsNullOrEmpty(Model.BudgetValu ...
- Flutter移动电商实战 --(38)路由_Fluro中Handler编写方法
在main.dart中初始化Fluro 编写handler 在lib下新建routers文件夹,表示里面要很多路由相关的文件 我们声明一个Handler,在里面handlerFunc固定的两个参数 重 ...