(poj 2253) Frogger 最短路上的最大路段
题目链接:http://poj.org/problem?id=2253
Description
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists' sunscreen, he wants to avoid swimming and instead reach her 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
The input will contain one or more test cases. The first line of each test case will contain the number of stones n (<=n<=). The next n lines each contain two integers xi,yi ( <= xi,yi <= ) representing the coordinates of stone #i. Stone # is Freddy's stone, stone #2 is Fiona's stone, the other n- stones are unoccupied. There's a blank line following each test case. Input is terminated by a value of zero (0) for n. Output
For each test case, print a line saying "Scenario #x" and a line saying "Frog Distance = y" where x is replaced by the test case number (they are numbered from ) and y is replaced by the appropriate real number, printed to three decimals. Put a blank line after each test case, even after the last one. Sample Input Sample Output Scenario #
Frog Distance = 5.000 Scenario #
Frog Distance = 1.414 Source
Ulm Local
题目大意:有一只青蛙想到另一只青蛙那,但是不能一次到位,他需要借助中间的石头跳跃,问他到另一只那走的最短路中的最长跳跃距离是多少?
方法:求到另一只青蛙的地方的最小生成树的最大距离。
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
#define met(a,b) memset(a,b,sizeof(a))
#define N 500
struct node
{
int x,y; }s[N];
int Map[N][N];
int dis[N],ans;
int vis[N];
void dij(int n)
{
met(vis,);
for(int i=;i<=n;i++)
dis[i]=Map[][i];
vis[]=;
for(int i=;i<n;i++)
{
int an=INF;
int k=-;
for(int j=;j<=n;j++)
{
if(!vis[j] && an>dis[j])
an=dis[k=j];
}
ans=max(ans,an);
if(k==)///当k==2已经到达另一只青蛙的坐标
return ;
vis[k]=;
for(int j=;j<=n;j++)
{
if(!vis[j])
dis[j]=min(dis[j],Map[k][j]);
} }
}
int main()
{
int n;
int con=;
while(scanf("%d",&n),n)
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
Map[i][j]=i==j?:INF;
}
for(int i=;i<=n;i++)
{
scanf("%d %d",&s[i].x,&s[i].y);
}
for(int i=;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
int ans=(s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y);
Map[i][j]=Map[j][i]=ans;
}
}
ans=-INF;
dij(n);
printf("Scenario #%d\n",con++);
printf("Frog Distance = %.3f\n\n",sqrt(ans));
}
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 ...
随机推荐
- python第一百零九天---Django 4
session :1. Session 基于Cookie做用户验证时:敏感信息不适合放在cookie中 a. Session原理 Cookie是保存在用户浏览器端的键值对 Session是保存在服务器 ...
- unix2dos和dos2unix处理换行问题
今天同事QQ给发来一个文件内容如下: 希望把文件内容转换为update table_name set col_name=第一列 where col_name=第二列;这种SQL格式,使用UE列模式秒秒 ...
- git-------基础知识(本地推送项目版本---github上)
创建Git仓库 一:初始化版本库:-git init 二:添加文件到缓存区:-git add --添加所有文件 是:加个点-列:git add . 三:查看仓库状态:-git status 四:添加 ...
- 排序算法之选择排序的思想以及Java实现
1 基本思想 选择排序的思想是,每一次从待排序的数据元素中选出最小(或最大)的一个元素,存放在序列的起始位置,直到全部待排序的数据元素排完. 2,算法的实现(Java) package Algorit ...
- 序列对象(bytearray, bytes,list, str, tuple)
列表: L.append(x) # x追加到L尾部 L.count(x) # 返回x在L中出现的次数 L.extend(m) # Iterable m的项追加到L末尾 L += m # 功能同L.ex ...
- SpringMVC-DispatcherServlet工作流程及web.xml配置
工作流程: Web中,无非是请求和响应: 在SpringMVC中,请求的第一站是DispatcherServlet,充当前端控制器角色: DispatcherServlet会查询一个或多个处理器映射( ...
- (转)Spring Boot (十九):使用 Spring Boot Actuator 监控应用
http://www.ityouknow.com/springboot/2018/02/06/spring-boot-actuator.html 微服务的特点决定了功能模块的部署是分布式的,大部分功能 ...
- centos7下安装docker(15.8docker跨主机容器通信总结)
性能:underlay网络的性能优于overlay.Overlay网络利用隧道技术,将数据包封装到UDP中进行传输,由于涉及数据包的封装和解封,存在额外的CPU和网络的开销,虽然几乎所有overlay ...
- js 文件引用传递参数
每天学习一点点 编程PDF电子书免费下载: http://www.shitanlife.com/code (function() {var hm = document.createElement(&q ...
- HashMap 1.7
1.关键属性与内部类 1.1属性 使用拉链法解决hash冲突的hash表,hash表里存了多少个元素.数组有多长以及当什么情况下需要扩容是重要的参数. transient Entry<K,V&g ...