Frogger

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 64864   Accepted: 20127

题目链接: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 (2<=n<=200). The next n lines each contain two integers xi,yi (0 <= xi,yi <= 1000) representing the coordinates of stone #i. Stone #1 is Freddy's 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:

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 1) 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:

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

题意:

在一个二维平面内,给出一些点的坐标,问从起点到终点距离最大值最小为多少。

题解:

思路和另外一道题有类似,可以看看那道题的题解:https://www.cnblogs.com/heyuhhh/p/10352107.html

都是利用贪心的思想去做,类比一下,想想就出来了。

我就直接给代码吧~

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = ;
int n;
int x[N],y[N],head[N],vis[N];
int tot;
double d[N];
double dis(int a,int b){
return sqrt((double)(x[a]-x[b])*(x[a]-x[b])+(double)(y[a]-y[b])*(y[a]-y[b]));
}
struct Edge{
int u,v,next;
double w;
}e[N*N<<];
struct node{
int u;
double d;
bool operator < (const node &A)const{
return d>A.d;
}
};
void adde(int u,int v,double w){
e[tot].v=v;e[tot].next=head[u];e[tot].w=w;head[u]=tot++;
}
void Dijkstra(int s){
priority_queue <node> q;
for(int i=;i<=n;i++) d[i]=INF;
memset(vis,,sizeof(vis));
node now;d[s]=;
now.d=;now.u=s;
q.push(now);
while(!q.empty()){
node cur = q.top();q.pop();
int u=cur.u;
if(vis[u]) continue ;
vis[u]=;
for(int i=head[u];i!=-;i=e[i].next){
int v=e[i].v;
if(d[v]>max(d[u],e[i].w)){
d[v]=max(d[u],e[i].w);
now.d=d[v];now.u=v;
q.push(now);
}
}
}
}
int main(){
int cnt =;
while(scanf("%d",&n)!=EOF){
if(n==) break ;
cnt++;
memset(head,-,sizeof(head));tot=;
for(int i=;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(i==j) continue ;
adde(i,j,dis(i,j));
}
}
Dijkstra();
printf("Scenario #%d\n",cnt);
printf("Frog Distance = %.3f\n",d[]);
printf("\n");
}
return ;
}

POJ2253:Frogger(改造Dijkstra)的更多相关文章

  1. POJ. 2253 Frogger (Dijkstra )

    POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...

  2. poj2253 Frogger Dijkstra变形

    题目链接:http://poj.org/problem?id=2253 就是求所有路径的最大边权值的最小值 处理时每次找出距离当前的已选的节点的最短距离,然后更新每个未选节点的值 代码: #inclu ...

  3. poj2253 Frogger dijkstra

    题目大意: 给出n个岛的坐标,前两个坐标分别为A青蛙和B青蛙所在岛的坐标,A青蛙想到达B青蛙所在的岛,A可以从某一个岛跳到任意其它一个岛上,则A到B的每条路径都有一个跳的最远的距离Xi,求这些最远距离 ...

  4. POJ 2253 Frogger(Dijkstra)

    传送门 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 39453   Accepted: 12691 Des ...

  5. POJ-2253 Frogger(最短路)

    https://vjudge.net/problem/POJ-2253 题意 公青蛙想到母青蛙那里去,期间有许多石头,公青蛙可以通过这些石头跳过去.问至少要跳的最大距离,即所有路径上石头间的最大距离的 ...

  6. poj 2253 Frogger (dijkstra最短路)

    题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  7. POJ2253 Frogger —— 最短路变形

    题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  8. POJ 2253 Frogger(dijkstra 最短路

    POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...

  9. poj2253 Frogger(最短路变型或者最小生成树)

    /* 题意:就是源点到终点有多条的路径,每一条路径中都有一段最大的距离! 求这些路径中最大距离的最小值! Dijkstra, Floyd, spfa都是可以的!只不过是将松弛的条件变一下就行了! 想了 ...

随机推荐

  1. 官方yum源安装选择所需版本mysql数据库并初始化(yum默认安装的是最新版MySQL8.+)

    在官网是找不到5.x系列的域名源的,系统默认是安装的oracle数据库,在安装前需要删除默认的 以下教程来源于官网说明 先去官网下载yum源,地址 https://dev.mysql.com/down ...

  2. 网络基础,tpc,udp

    一 , 网络基础相关知识 1. 架构 (重点) C / S  架构 : client 客户端(APP) 和 server 服务器端 能充分发挥pc机的性能 B / S 架构 : browser 浏览器 ...

  3. ScriptManager和UpdatePanel用法 (ajax)

    ScriptManager和UpdatePanel控件联合使用可以实现页面异步局部更新的效果.其中的UpdatePanel就是设置页面中异 步局部更新区域,它必须依赖于ScriptManager存在, ...

  4. R语言学习笔记(十四):零碎知识点(41-45)

    41--ls( ) ls()可以用来列出现存的所有对象. pattern是一个具名参数,可以列出所有名称中含有字符串"s"的对象. > ls() [1] "s&qu ...

  5. R语言学习笔记(十三):零碎知识点(36-40)

    36--diag() 如果它的参数是一个矩阵,它返回的是一个向量 如果它的参数是一个向量,它返回的是一个向量 如果它的参数是一个标量,它返回的是指定大小的单位矩阵 > diag(2) [,1] ...

  6. Java——英文字母---18.10.11

    package lianxi;import java.io.*;import java.util.Scanner;public class file{  public static void main ...

  7. 分布式redis一些小结

    本文围绕以下几点进行阐述: 为什么使用 Redis 使用 Redis 有什么缺点 单线程的 Redis 为什么这么快 Redis 的数据类型,以及每种数据类型的使用场景 Redis 的过期策略以及内存 ...

  8. Java - 问题集 - 导出csv文件中文乱码

    微软的excel文件需要通过文件头的bom来识别编码,所以写文件时,需要先写入bom头. FileOutputStream fos = new FileOutputStream(new File(&q ...

  9. win10 java环境变量配置

    首先,你应该已经安装了 Java 的 JDK 了(如果没有安装JDK,请跳转到此网址:http://www.oracle.com/technetwork/java/javase/downloads/i ...

  10. PHP二维数组按某个键值排序

    $data=Array(    [0] => Array        (            [id] => 2            [user_id] => 14       ...