poj 2253 Frogger (最短路径)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 22557 | Accepted: 7339 |
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
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
//348K 0MS C++ 1240B 2013-11-23 09:00:29
/* 题意:
给出n个石头,互相连通,青蛙要从第一个石头跳到第二个,求所有通路中最小的
各通路的最大跨步. 最短路径:
dij小变形,有点巧妙..看代码慢慢体会 */
#include<stdio.h>
#include<string.h>
#include<math.h>
struct node{
int x,y;
}p[];
int g[][];
int d[];
bool vis[];
int n;
int dis(node a,node b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int max(int a,int b)
{
return a>b?a:b;
}
int min(int a,int b)
{
return a<b?a:b;
}
double dij()
{
memset(vis,false,sizeof(vis));
for(int i=;i<n;i++){
d[i]=g[][i];
}
vis[]=true;
while(!vis[]){ //遍历过第二个石头后就可跳出
int temp=0x7ffffff;
int v=;
for(int j=;j<n;j++)
if(!vis[j] && temp>d[j]){
temp=d[j];
v=j;
}
vis[v]=true;
for(int j=;j<n;j++)
if(!vis[j])
d[j]=min(max(d[v],g[v][j]),d[j]); //最小的最大步长
}
return sqrt(1.0*d[]);
}
int main(void)
{
int k=;
while(scanf("%d",&n),n)
{
for(int i=;i<n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
for(int i=;i<n;i++)
for(int j=i+;j<n;j++)
g[i][j]=g[j][i]=dis(p[i],p[j]);
double ans=dij();
printf("Scenario #%d\n",k++);
printf("Frog Distance = %.3lf\n\n",ans);
}
return ;
}
floyd:
//348K 47MS C++ 943B 2013-11-23 09:19:27
#include<stdio.h>
#include<string.h>
#include<math.h>
struct node{
int x,y;
}p[];
int g[][];
int n;
int dis(node a,node b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int Max(int a,int b)
{
return a>b?a:b;
}
double floyd()
{
for(int k=;k<n;k++)
for(int i=;i<n-;i++)
for(int j=i+;j<n;j++)
if(g[i][k]<g[i][j] && g[k][j]<g[i][j])
g[i][j]=g[j][i]=Max(g[i][k],g[k][j]);
return sqrt(1.0*g[][]);
}
int main(void)
{
int k=;
while(scanf("%d",&n),n)
{
for(int i=;i<n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
for(int i=;i<n-;i++)
for(int j=i+;j<n;j++)
g[i][j]=g[j][i]=dis(p[i],p[j]);
double ans=floyd();
printf("Scenario #%d\n",k++);
printf("Frog Distance = %.3lf\n\n",ans);
}
return ;
}
注意小细节:使用G++交的话要把printf中的 lf 改成 f ,否则会报错!
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
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))
传送门: 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 ...
随机推荐
- Python简单线程间通信
本节主要举一个简单的线程间通信的例子,利用线程安全的数据结构queue.Queue保存线程间通信的内容, import queue from threading import Thread from ...
- 牛客小白月赛2 G 文 【模拟】
链接:https://www.nowcoder.com/acm/contest/86/G来源:牛客网 题目描述 Sεlιнα(Selina) 开始了新一轮的男友海选.她要求她的男友要德智体美劳样样都全 ...
- Eclipse中文乱码解决方案
Eclipse中文乱码解决方案 1)第一个设置:window>perferences>general>workspace>text file encoding 2)Jsp编码问 ...
- Element-ui组件--pagination分页
一般写后台系统都会有很多的列表,有列表就相应的要用到分页,根据项目中写的几个分页写一下我对分页的理解,就当是学习笔记了. 这是Element-ui提供的完整的例子 <template> ...
- scrapy--boss直聘
Hi,大家好.有段时间没来更新scrapy爬取实例信息了,前2天同事说爬取拉勾,boss直聘等网站信息比较困难.昨天下午开始着手爬取boss直聘内Python爬虫的信息,比想象中的简单很多. 需要解决 ...
- HTML常用标签用法及实例
HTML常用标签用法及实例1.<!--1.注释-->2.<!--2.DOCTPYE 声明文档类型-->3.<!--3.a--> <a href="h ...
- JZOJ 3534. 【NOIP2013提高组day1】货车运输
Description A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货物,司机们想知道每辆车在不超过车辆限重的 ...
- 基于pandas进行数据预处理
很久没用pandas,有些有点忘了,转载一个比较完整的利用pandas进行数据预处理的博文:https://blog.csdn.net/u014400239/article/details/70846 ...
- Git-改变历史
悔棋 在日常的Git操作中,会经常出现这样的状况,输入git commit命令刚刚敲下回车键就后悔了:可能是提交说明中出现了错别字,或者有文件忘记提交,或者有的修改不应该提交,诸如此类. Git提供了 ...
- Android学习记录(4)—在java中学习多线程下载的基本原理和基本用法①
多线程下载在我们生活中非常常见,比如迅雷就是我们常用的多线程的下载工具,当然还有断点续传,断点续传我们在下一节来讲,android手机端下载文件时也可以用多线程下载,我们这里是在java中写一个测试, ...