POJ 2253-Frogger(最小生成树的最大权)
原题链接:点击此处
题意:
一只叫Freddy的青蛙蹲坐在湖中的一块石头上。突然他发现一只叫Fiona的青蛙在湖中的另一块石头上。Freddy想要跟Fiona约会,但由于湖水太脏,他不想游泳过去而是跳过去找Fiona。
很不幸,Fiona所在的石头距离他有点远,甚至超出了他的跳跃能力。然而Freddy注意到湖中还有一些其他的石头。这些石头也许会将这个很长的跳跃距离化成若干个短的跳跃距离。
我们定义“青蛙距离”为Freddy跳到Fiona那里所需要的若干次跳跃中最长的那一次。现在给你Freddy,Fiona,以及湖中其他石头的坐标,让你求出最短的“青蛙距离”。
输入有可能是多组测试数据。每组数据的第一行有一个整数n(<=n<=),表示湖中一共有多少块石头。接下来的n行,每一行有两个整数xi,yi( <= xi,yi <= ),表示第i块石头的坐标。第1块石头的坐标是Freddy所在的位置,第二块石头的坐标是Fiona所在的位置,其他的石头上都没有青蛙。当输入n=0的时候,程序结束。 对于每一组测试数据,先输出一行"Scenario #x",然后在下一行输出"Frog Distance = y"。其中x表示当前是第几组测试数据,y为该组数据的最小“青蛙距离”。每两组测试数据之间输出一个空行。
看来题目好久都没看懂到底求得是什么,后来才知道求得事最小生成树的最大权。既然如此就用Dijkstra算法吧!
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
const int maxn=; pair<int,int>p[maxn];
double d[maxn][maxn]; double dis(pair<int,int>p1,pair<int,int>p2)
{
return sqrt((double)(p1.first-p2.first)*(p1.first-p2.first)+(p2.second-p1.second)*(p2.second-p1.second));
} int main()
{
int n,x,y;
int flag=;
while(scanf("%d",&n)&&n)
{
flag++;
printf("Scenario #%d\n",flag);
for(int i=;i<n;i++)
{
scanf("%d%d",&x,&y);
p[i]=make_pair(x,y);
}
for(int i=;i<n;i++)
for(int j=;j<n;j++)
{
d[j][i]=d[i][j]=dis(p[i],p[j]);
}
for(int k=;k<n;k++)
for(int i=;i<n;i++)
for(int j=;j<n;j++)
if(d[i][j]>max(d[i][k],d[k][j]))
d[i][j]=max(d[i][k],d[k][j]);
printf("Frog Distance = %.3f\n\n",d[][]);
}
return ;
}
POJ 2253-Frogger(最小生成树的最大权)的更多相关文章
- 最短路(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 最小瓶颈路(变形的最小生成树 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 (dijkstra最短路)
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】
Frogger Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- POJ 2253 Frogger Floyd
原题链接: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多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...
随机推荐
- MyBatis和Hibernate相比较
作者:乌拉拉链接:http://www.zhihu.com/question/21104468/answer/58579295 1.开发对比开发速度 Hibernate的真正掌握要比Mybatis来得 ...
- 云存储上传控件(cloud2)-Xproer.HttpUploader7
版权所有 2009-2016 荆门泽优软件有限公司 保留所有权利 官方网站:http://www.ncmem.com/ 产品首页:http://www.ncmem.com/webapp/cloud2/ ...
- SpringMVC源码解读 - RequestMapping注解实现解读 - RequestCondition体系
一般我们开发时,使用最多的还是@RequestMapping注解方式. @RequestMapping(value = "/", param = "role=guest& ...
- winform 中TextBox只能输入数字
textBox1.KeyPress+=TextNumber_KeyPress; private void TextNumber_KeyPress(object sender, KeyPressEven ...
- jquery插件中(function ( $, window, document, undefined )的作用
在jquery插件中我们经常看到以下这段代码 ;(function ( $, window, document, undefined ){ //函数体内具体代码 })(jQuery, window,d ...
- CodeForces 907F Power Tower(扩展欧拉定理)
Priests of the Quetzalcoatl cult want to build a tower to represent a power of their god. Tower is u ...
- centos 7 安装jdk8
到官网下载jdk http://www.oracle.com/technetwork/java/javase/downloads/index.html 选择liunx的tar.gz文件下载 下载好后 ...
- js 格式化时间
//格式化时间 function time_format(time) { return new Date(parseInt(time) * 1000).toLocaleString().replace ...
- Java50道经典习题-程序2 输出素数
题目:判断101-200之间有多少个素数,并输出所有素数 分析:判断素数的方法:用一个数分别去除2到(这个数-1)的数,如果能被整除,则表明此数不是素数,反之是素数. public class Pro ...
- Centos故障01:Docker容器丢失
问题 一测试环境,配置及应用如下: [Centos ~]# rpm -q centos-release centos-release-7-6.1810.2.el7.centos.x86_64 应用: ...