(POJ2253)Frog
来源:互联网 发布:win7禁止修改ip软件 编辑:程序博客网 时间:2024/06/15 03:06
Description
Unfortunately Fiona's stone is out of his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach her by a sequence of several small jumps.
To execute a given sequence of jumps, a frog's jump range obviously must be at least as long as the longest jump occuring in the sequence.
The frog distance (humans also call it minimax distance) between two stones therefore is defined as the minimum necessary jump range over all possible paths between the two stones.
You are given the coordinates of Freddy's stone, Fiona's stone and all other stones in the lake. Your job is to compute the frog distance between Freddy's and Fiona's stone.
Input
Output
Sample Input
20 03 4317 419 418 50
Sample Output
Scenario #1Frog Distance = 5.000Scenario #2Frog Distance = 1.414
复制一下别人的题意,有两只青蛙和若干块石头,现在已知这些东西的坐标,两只青蛙A坐标和青蛙B坐标是第一个和第二个坐标,现在A青蛙想要到B青蛙那里去,并且A青蛙可以借助任意石头的跳跃,而从A到B有若干通路,问从A到B的所有通路上的最大边,比如有 有两条通路 1(4)5 (3)2 代表1到5之间的边为4, 5到2之间的边为3,那么该条通路跳跃范围(两块石头之间的最大距离)为 4, 另一条通路 1(6) 4(1) 2 ,该条通路的跳跃范围为6, 两条通路的跳跃范围分别是 4 ,6,我们要求的就是最小的那一个跳跃范围,即4。
底下是Floyd解法。
基本思路很明确,首先在读入数据的时候用两点间的距离公式,算出每两点间的距离map[i][j](等于map[j][i]);
然后
void floyd()
{
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
mapp[i][j] = min(mapp[i][j],max(mapp[i][k],mapp[k][j]));
}
以k为跳板,进行n-1次松弛操作.......
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define maxn 210
double mapp[maxn][maxn];
int x[maxn],y[maxn];
int n;
double dis(double x1,double x2,double y1,double y2)
{
double ans = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
return ans;
}
void floyd()
{
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
mapp[i][j] = min(mapp[i][j],max(mapp[i][k],mapp[k][j]));
}
int main()
{
//freopen("d://test.txt","r",stdin);
int kase = 1;
while(scanf("%d", &n)!=EOF && n!=0)
{
memset(mapp,0,sizeof(mapp));
for(int i=1;i<=n;i++)
scanf("%d%d", &x[i], &y[i]);
for(int i=1;i<=n;i++)
for(int j = 1;j<=n;j++)
mapp[i][j] = mapp[j][i] = dis(x[i],x[j],y[i],y[j]);
floyd();
printf("Scenario #%d\nFrog Distance = %.3lf\n\n",kase++,mapp[1][2]);
}
return 0;
}
- (POJ2253)Frog
- Frog Distance(poj2253)flo…
- poj2253 frog之最小生成树prim解法
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- tcpdump
- 缓存identifier of an instance of com.topsec.tss.web.model.event.Event was altered from … to …
- ubuntu16.04配置caffe遇到的问题
- 非常详细的Docker学习教程
- centOS7 mini配置jdk
- (POJ2253)Frog
- 文章标题
- Ubuntu16.04 64bits安装docker
- 无偿加班竟然被开除,程序员坐不住了
- 文档管理控件Xshell 发布v6 Beta版本,引入会话管理器面板丨附下载
- 分支限界法
- 窗口管理
- Redis 学习笔记(三)之散列类型命令
- React Native 常见错误汇总