poj 2253 Frogger(floyd变形)
题目链接:http://poj.org/problem?id=1797
题意:给出两只青蛙的坐标A、B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的。显然从A到B存在至少一条的通路,每一条通路的元素都是这条通路中前后两个点的距离,这些距离中又有一个最大距离。现在要求求出所有通路的最大距离,并把这些最大距离作比较,把最小的一个最大距离作为青蛙的最小跳远距离。
有一个明显的方法就是dfs一遍但是肯定会te,所以可以考虑一下用dp的思想。
类似记忆化搜索的思想,由于数据比较小所以不用记忆化搜索也行直接利用套3层for
dp[i][j]表示从i点到j点的minimax distance(就是题目所要求的)mmp[i][j]表示i
点到j点的距离。
for(int k = 1 ; k <= n ; k++) {
for(int i = 1 ; i <= n ; i++) {
for(int j = 1 ; j <= n ; j++) {
MIN = max(mmp[i][k] , mmp[k][j]);
MIN2 = max(dp[i][k] , dp[k][j]);
dp[i][j] = min(dp[i][j] , min(MIN , MIN2));
dp[j][i] = dp[i][j];
}
}
}
其实这3层for也是利用了floyd的思想。
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdio>
using namespace std;
double mmp[210][210] , dp[210][210] , MIN , MIN2;
int n , x , y;
struct TnT {
int x , y , num;
};
bool vis[220]; int main() {
int ans = 0;
while(scanf("%d" , &n)) {
ans++;
if(!n)
break;
TnT T[210];
for(int i = 1 ; i <= n ; i++) {
scanf("%d%d" , &x , &y);
T[i].num = i;
T[i].x = x;
T[i].y = y;
}
for(int i = 1 ; i <= n ; i++) {
for(int j = 1 ; j <= n ; j++) {
mmp[i][j] = (double)400000;
dp[i][j] = (double)400000;
}
}
for(int i = 1 ; i <= n; i++) {
int x1 = T[i].x , y1 = T[i].y , pos1 = T[i].num , x2 , y2 , pos2 , m;
for(int j = 1 ; j <= n ; j++) {
x2 = T[j].x , y2 = T[j].y , pos2 = T[j].num;
m = 1.0 * (x1 - x2) * (x1 - x2) + 1.0 * (y1 - y2) * (y1 - y2);
mmp[pos1][pos2] = min(mmp[pos1][pos2] , 1.0 * sqrt(double(m)));
mmp[pos2][pos1] = min(mmp[pos1][pos2] , mmp[pos2][pos1]);
}
}
for(int k = 1 ; k <= n ; k++) {
for(int i = 1 ; i <= n ; i++) {
for(int j = 1 ; j <= n ; j++) {
MIN = max(mmp[i][k] , mmp[k][j]);
MIN2 = max(dp[i][k] , dp[k][j]);
dp[i][j] = min(dp[i][j] , min(MIN , MIN2));
dp[j][i] = dp[i][j];
}
}
}
printf("Scenario #%d\n" , ans);
printf("Frog Distance = %.3f\n\n" , dp[1][2]);
}
return 0;
}
poj 2253 Frogger(floyd变形)的更多相关文章
- POJ 2253 Frogger Floyd
原题链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 Frogger floyd算法
题目:click here 题意: 给出两只青蛙的坐标A.B,和其他的n-2个坐标,任意两坐标间是双向连通的.显然从A到B存在至少一条的通路,每一条通路的元素都是这条通路中前后两个点的距离,这些距离中 ...
- 最短路(Floyd_Warshall) POJ 2253 Frogger
题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...
- POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)
POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...
- POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- POJ 2253 Frogger(dijkstra 最短路
POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...
- POJ 2253 Frogger【最短路变形——路径上最小的最大权】
链接: http://poj.org/problem?id=2253 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))
传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 Frogger
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ2253——Frogger(Floyd变形)
Frogger DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fi ...
随机推荐
- RocketMQ中Producer消息的发送
上篇博客介绍过Producer的启动,这里涉及到相关内容就不再累赘了 [RocketMQ中Producer的启动源码分析] Producer发送消息,首先需要生成Message实例: public c ...
- nginx lua集成kafka
NGINX lua集成kafka 第一步:进入opresty目录 [root@node03 openresty]# cd /export/servers/openresty/ [root@node03 ...
- 自定义SWT控件五之自定义穿梭框
5.自定义穿梭框 package com.view.control.shuttlebox; import java.util.ArrayList; import java.util.HashMap; ...
- ArrayList 的使用方法【摘要】
ArrayList 的使用方法 1.什么是ArrayList ArrayList就是传说中的动态数组,用MSDN中的说法,就是Array的复杂版本,它提供了如下一些好处: (1)动态的增加和减少元素 ...
- Why do I write a blog
I believe the most beautiful and elegant answer to this question is from Churchill. "On a peace ...
- 逆向破解之160个CrackMe —— 002-003
CrackMe —— 002 160 CrackMe 是比较适合新手学习逆向破解的CrackMe的一个集合一共160个待逆向破解的程序 CrackMe:它们都是一些公开给别人尝试破解的小程序,制作 c ...
- 使用抽象工厂反射获取不到Dal层对象,未能加载文件或程序集......
Put aside the fog and see the essence 解决问题之前,要明白问题为什么会出现 我相信能点开这篇帖子的人,都是具有探索精神的人,因为,只有心存疑问才会搜索 如果只想单 ...
- eclipse解决properties文件中文乱码(两种方试)
第一种:大多数网上搜到的情况(不靠谱) 第一步:windows-->properties-->General-->Content Types-->text(如下图) 第二步:p ...
- idea中的springboot项目如何不用重新编译,自动热部署
两步走:引入依赖,配置idea 在pom.xml中引入如下依赖,关键字:devtools 第二步,修改idea两处配置 2.1 windows下,ctl+alt+s打开idea配置菜单 左上角输入框搜 ...
- hadoop学习(五)----HDFS的java操作
前面我们基本学习了HDFS的原理,hadoop环境的搭建,下面开始正式的实践,语言以java为主.这一节来看一下HDFS的java操作. 1 环境准备 上一篇说了windows下搭建hadoop环境, ...