POJ 2253 Frogger(warshall算法)
题意:湖中有很多石头,两只青蛙分别位于两块石头上。其中一只青蛙要经过一系列的跳跃,先跳到其他石头上,最后跳到另一只青蛙那里。目的是求出所有路径中最大变长的最小值(就是在到达目的地的路径中,找出青蛙需要跳跃的最大边长的最小的值)。
思路:warshall算法
hint:似懂非懂
课本代码:
#include<iostream>
#include<cmath>
#include<stdio.h>
#include<cstring>
bool con[210][210];
double L[210][210];
double x[210];
double y[210];
using namespace std;
int main(){
int N,testcase=0; while(scanf("%d",&N)&&N!=0){
memset(con,0,sizeof(con));
memset(L,0,sizeof(L));
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
int i,j,k;
for(i=0;i<N;i++){
scanf("%lf",&x[i]);
scanf("%lf",&y[i]);
}
double l=0,r=1e5;//区间的左右指针初始化
for(i=0;i<N;i++)//计算边长矩阵L
for(j=0;j<N;j++)
L[i][j]=sqrt( (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]) );
while(r-l>=1e-5){
double mid=(l+r)/2;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
if(L[i][j]>mid) con[i][j]=false;//边长大于中间值
else con[i][j]=true;//边长不大于中间值
for(k=0;k<N;k++)//在边长不超过mid的情况下计算可达的节点对标志con
for(i=0;i<N;i++)
for(j=0;j<N;j++)
con[i][j]|=con[i][k]&con[k][j];
if(con[0][1]) r=mid;//若节点0至节点1的边长不超过mid,则最长边的最小值在左区间;否则在右区间
else l=mid;
}
printf("Scenario #%d\n",++testcase);
printf("Frog Distance = %.3f\n",l);
printf("\n");
}
return 0;
}
POJ 2253 Frogger(warshall算法)的更多相关文章
- poj 2253 Frogger dijkstra算法实现
点击打开链接 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21653 Accepted: 7042 D ...
- 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 (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- 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 最小瓶颈路(变形的最小生成树 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 ...
- poj 2253 Frogger (最长路中的最短路)
链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...
随机推荐
- 题目1 : Farthest Point
时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 Given a circle on a two-dimentional plane. Output the integral ...
- 如何更好的利用Node.js的性能极限
通过使用非阻塞.事件驱动的I/O操作,Node.js为构建和运行大规模网络应用及服务提供了很好的平台,也受到了广泛的欢迎.其主要特性表现为能够处理庞大的并且高吞吐量的并发连接,从而构建高性能.高扩展性 ...
- js校验密码强度
网上转载的一段代码,留着以后用, js文件: //判断输入密码的类型 function CharMode(iN){ if (iN>=48 && iN <=57) //数字 ...
- CAFFE学习笔记(二)Caffe_Example之测试mnist
这一次的博客将接着上一次的内容,简单讲解一下如何使用训练后的网络lenet_iter_5000.caffemodel与lenet_iter_10000.caffemodel. 1.在网络训练完毕后,将 ...
- Aeroplane chess(简单概率dp)
Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz start ...
- Pairs of Integers
Pairs of Integers You are to find all pairs of integers such that their sum is equal to the given in ...
- 九度OJ 1252:回文子串 (字符串处理、DP)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:387 解决:224 题目描述: 输入一个字符串,输出该字符串中对称的子字符串的最大长度. 比如输入字符串"google" ...
- Ubuntu 下安装JDK1.8
好困,不行了,我要睡觉了,先上图吧!
- nginx学习之静态内容篇(五)
1.根目录和索引文件 server { root /www/data; location / { } location /images/ { } location ~ \.(mp3|mp4) { ro ...
- Android笔记之OnLongClickListener
OnLongClickListener中的回调函数boolean onLongClick(View v),其返回值的官方释义如下 如果这个回调消耗了长点击,则返回true,否则返回false. 即使翻 ...