POJ 2253 Frogger(最短路&Floyd)题解
题意:想给你公青蛙位置,再给你母青蛙位置,然后给你剩余位置,问你怎么走,公青蛙全力跳的的最远距离最小。
思路:这里不是求最短路径,而是要你找一条路,青蛙走这条路时,对他跳远要求最低。这个思想还是挺好迁移的,原来我们用mp[i][j]表示i到j最短路径,那么我们现在用它表示i到j最大步伐,然后每次比较,只要最大步伐比他小,那么我们就走新的路。注意最后是mp[1][2],一直mp[1][n]没改无限WA。
代码;
#include<cstdio>
#include<set>
#include<cmath>
#include<stack>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = 200+5;
const int INF = 0x3f3f3f3f;
struct Node{
double x,y;
}node[maxn];
double mp[maxn][maxn]; //表示i->j的最大步伐
int Case = 1;
void Floyd(int n){
for(int k = 1;k <= n;k++){
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
if(mp[i][j] > max(mp[i][k],mp[k][j])){ //这样走最大步伐比较小
mp[i][j] = mp[j][i]= max(mp[i][k],mp[k][j]);
}
}
}
}
printf("Scenario #%d\nFrog Distance = %.3lf\n\n",Case++,mp[1][2]);
}
int main(){
int n,m;
while(~scanf("%d",&n) && n){
for(int i = 1;i <= n;i++)
scanf("%lf%lf",&node[i].x,&node[i].y);
for(int i = 1;i <= n;i++){
for(int j = i + 1;j <= n;j++){
mp[i][j] = mp[j][i] = sqrt((node[i].x - node[j].x)*(node[i].x - node[j].x) +
(node[i].y - node[j].y)*(node[i].y - node[j].y));
}
}
Floyd(n);
}
return 0;
}
POJ 2253 Frogger(最短路&Floyd)题解的更多相关文章
- poj 2253 Frogger(最短路 floyd)
题目:http://poj.org/problem?id=2253 题意:给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通路的元 ...
- POJ 2253 Frogger 最短路 难度:0
http://poj.org/problem?id=2253 #include <iostream> #include <queue> #include <cmath&g ...
- POJ 2253 Frogger ( 最短路变形 || 最小生成树 )
题意 : 给出二维平面上 N 个点,前两个点为起点和终点,问你从起点到终点的所有路径中拥有最短两点间距是多少. 分析 : ① 考虑最小生成树中 Kruskal 算法,在建树的过程中贪心的从最小的边一个 ...
- POJ 2253 Frogger -- 最短路变形
这题的坑点在POJ输出double不能用%.lf而要用%.f...真是神坑. 题意:给出一个无向图,求节点1到2之间的最大边的边权的最小值. 算法:Dijkstra 题目每次选择权值最小的边进行延伸访 ...
- POJ 2253 Frogger (最短路)
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28333 Accepted: 9208 Descript ...
- 最短路(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 Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...
- POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- POJ 2253 Frogger Floyd
原题链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
随机推荐
- JS-【同页面多次调用】轮播特效封装-json传多个参数
看着传那么一长串的参数神烦,继续深化!——json传参: html: <div class="scrollBanner"> <ul class="ban ...
- Ubuntu16.04安装Elasticsearch
一.安装工作 wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - sudo apt-g ...
- 【BZOJ2768】[JLOI2010]冠军调查/【BZOJ1934】[Shoi2007]Vote 善意的投票 最小割
[BZOJ2768][JLOI2010]冠军调查 Description 一年一度的欧洲足球冠军联赛已经进入了淘汰赛阶段.随着卫冕冠军巴萨罗那的淘汰,英超劲旅切尔西成为了头号热门.新浪体育最近在吉林教 ...
- Hibernate--快速上手
一.初识 Hibernate 经典的软件应用体系结构有三层:表示层(提供了与用户交互的接口,实现用户操作界面,展示用户需要的数据).业务逻辑层(完成业务流程,处理表示层提交的数据请求,并将要保存的数据 ...
- centos7修改网卡名、密码重置
修改网卡名称 编辑 /etc/sysconfig/grub 倒数第二行quiet 后加入 net.ifnames=0 biosdevname=0 执行 grub2-mkconfig -o /bo ...
- 牛客网多校赛第七场A--Minimum Cost Perfect Matching【位运算】【规律】
链接:https://www.nowcoder.com/acm/contest/145/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...
- python tensorflow keras
pip install tensorflow pip install keras pip install theano http://www.open-open.com/lib/view/open14 ...
- 棋盘游戏---hdu1281(最大匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 题目大意:就是车和车之间不能发生攻击.还有一部分位置不可以放置棋子. 解题思路:一行一列 ...
- Redis缓冲区设置
对于Redis服务器的输出(也就是命令的返回值)来说,其大小通常是不可控制的.有可能一个简单的命令,能够产生体积庞大的返回数据.另外也有可能因为执行了太多命令,导致产生返回数据的速率超过了往客户端发送 ...
- python修改镜像源
pip升级:python -m pip install --upgrade pip https://www.cnblogs.com/andy9468/p/10319442.html 1.在命令中临时修 ...