POJ2253 Frogger
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 34865 | Accepted: 11192 |
Description
by jumping.
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
stone, stone #2 is Fiona's stone, the other n-2 stones are unoccupied. There's a blank line following each test case. Input is terminated by a value of zero (0) for n.
Output
after each test case, even after the last one.
Sample Input
2
0 0
3 4 3
17 4
19 4
18 5 0
Sample Output
Scenario #1
Frog Distance = 5.000 Scenario #2
Frog Distance = 1.414
Source
因为已经限定了两只青蛙在石头1和2上,所以是单源最短路径问题
跑了遍floyd就过了
求青蛙距离:map[i][j]=min(map[i][j],max(map[i][k],map[k][j])
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int mxn=;
int x[mxn],y[mxn];//石头坐标
double mp[][];//图
int n;
double dis(int x1,int x2,int y1,int y2){//求两点间距离
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
void cdis(){//将两点间距离存入邻接矩阵
memset(mp,,sizeof());
int i,j;
for(i=;i<=n;i++)
for(j=;j<=n;j++){
mp[i][j]=dis(x[i],x[j],y[i],y[j]);
}
return;
}
int main(){
int T=;
while(scanf("%d",&n) && n){
printf("Scenario #%d\n",++T);
int i,j;
for(i=;i<=n;i++){
scanf("%d%d",&x[i],&y[i]);
}
cdis();
for(int k=;k<=n;k++)
for(i=;i<=n;i++)
for(j=;j<=n;j++){
mp[i][j]=min(mp[i][j],max(mp[i][k],mp[k][j]));
// printf("%d %d %d\n",k,i,j);
// printf("%.3f %.3f %.3f\n",mp[i][j],mp[i][k],mp[k][j]);
}
printf("Frog Distance = %.3f\n\n",mp[][]);//注意空行
}
return ;
}
POJ2253 Frogger的更多相关文章
- POJ2253——Frogger(Floyd变形)
Frogger DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fi ...
- POJ-2253 Frogger(最短路)
https://vjudge.net/problem/POJ-2253 题意 公青蛙想到母青蛙那里去,期间有许多石头,公青蛙可以通过这些石头跳过去.问至少要跳的最大距离,即所有路径上石头间的最大距离的 ...
- poj2253 Frogger(Floyd)
题目链接 http://poj.org/problem?id=2253 题意 给出青蛙A,B和若干石头的坐标,现在青蛙A要跳到青蛙B所在的石头上,求出所有路径中最远那一跳的最小值. 思路 Floyd算 ...
- POJ2253 Frogger —— 最短路变形
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ-2253 Frogger dijsktra查找间隔最小的路径
题目链接:https://cn.vjudge.net/problem/POJ-2253 题意 一只Forg需要从节点1走到节点n 现要找一条各个间隔最小的路径 问间隔最小是多少 思路 用dijsktr ...
- poj2253 Frogger(最短路变型或者最小生成树)
/* 题意:就是源点到终点有多条的路径,每一条路径中都有一段最大的距离! 求这些路径中最大距离的最小值! Dijkstra, Floyd, spfa都是可以的!只不过是将松弛的条件变一下就行了! 想了 ...
- POJ2253 Frogger(最短路)
题目链接. 题意: 从0号点,到1号点,找一条能通过的路,使得这条路中的最大的边,比其它所有可能的路中的边都小. 分析: 这题就是按着dijkstra写,写着写着觉得像是prim了. 其中d[n]表示 ...
- poj2253 Frogger Dijkstra变形
题目链接:http://poj.org/problem?id=2253 就是求所有路径的最大边权值的最小值 处理时每次找出距离当前的已选的节点的最短距离,然后更新每个未选节点的值 代码: #inclu ...
- POJ-2253.Frogger.(求每条路径中最大值的最小值,最短路变形)
做到了这个题,感觉网上的博客是真的水,只有kuangbin大神一句话就点醒了我,所以我写这篇博客是为了让最短路的入门者尽快脱坑...... 本题思路:本题是最短路的变形,要求出最短路中的最大跳跃距离, ...
随机推荐
- ArrayList和Hashtable
public class Tools{ public string Name{get ;set;}} #region 0.1ArrayList集合 ////告诉内存,我要存储内容 //ArrayLis ...
- linux上的常见命令掌握
http://coolshell.cn/articles/8883.html 这篇文章来源于Quroa的一个问答<What are some time-saving tips that ever ...
- 【转】【Asp.Net】ASP.NET中自定义控件无法响应事件
在自定义服务器控件中增加事件处理程序,但代码运行时没有错误,按钮点击下去却没有反应.应该如何处理呢?(本例中,该自定义控件包括一个Button,和一个Label,我希望用户点击了这个Button后,改 ...
- C#中小数点后保留两位小数,四舍五入的函数及使用方法
Math.Round(45.367,2) //Returns 45.37 Math.Round(45.365,2) //Returns 45.36 C#中的Round()不是我 ...
- 异步编程 In .NET(转)
转自:http://www.cnblogs.com/jesse2013/p/Asynchronous-Programming-In-DotNet.html 概述 在之前写的一篇关于async和awai ...
- [CareerCup] 7.2 Ants on Polygon 多边形上的蚂蚁
7.2 There are three ants on different vertices of a triangle. What is the probability of collision ( ...
- swifter技巧(100)
一.swift新元素 Tip1:柯里化 将方法进行柯里化,把接受多个参数的方法变换成接受第一个参数的方法,并且返回接受余下的参数,返回结果的新方法. func addTwoNumbers(a: Int ...
- 34 Sources for Test Ideas
We recommend collecting test ideas continuously from a variety of information sources. Consider the ...
- 用Canvas玩3D:点-线-面
声明:本文为原创文章,如需转载,请注明来源WAxes,谢谢! 玩Canvas玩了有两三个礼拜了,平面的东西玩来玩去也就那样,所以就开始折腾3D了. 因为Canvas画布终究还是平面的,所以要有3D就得 ...
- c# r3 inline hook
前言 老婆喜欢在QQ游戏玩拖拉机,且安装了一个记牌器小软件,打开的时候弹出几个IE页面加载很多广告,于是叫我去掉广告.想想可以用OD进行nop填充,也可以写api hook替换shellexecute ...