题目链接:http://poj.org/problem?id=2253
Frogger

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 31114   Accepted: 10027

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

题意:
从起点到终点会有很多路径,每条路径上的边有一个最大值,求这些最大值中的最小值。
也就是更新的边要保持最大边。
Floyd
 #include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std; #define INF 0x3f3f3f3f
#define N 300
struct node
{
int x, y;
}; double dist[N];
double G[N][N];
int vis[N], n; void IN()
{
memset(vis, , sizeof(vis)); for(int i=; i<=n; i++)
{
dist[i]=INF;
for(int j=; j<=i; j++)
G[i][j]=G[j][i]=INF;
}
} void Floyd()
{
for(int k=; k<=n; k++)
{
for(int j=; j<=n; j++)
{
for(int i=; i<=n; i++)
{
if(G[j][i] > max(G[j][k], G[k][i]))
G[j][i] = max(G[j][k], G[k][i]);
}
}
}
} int main()
{
int i, j, t=; while(scanf("%d", &n), n)
{
double w;
node s[N];
memset(s, , sizeof(s));
IN(); for(i=; i<=n; i++)
scanf("%d%d", &s[i].x, &s[i].y); for(i=; i<n; i++)
for(j=i+; j<=n; j++)
{
w = sqrt((s[i].x-s[j].x)*(s[i].x-s[j].x)*1.0 + (s[i].y-s[j].y)*(s[i].y-s[j].y)*1.0);
G[i][j] = G[j][i]=min(G[i][j], w);
} printf("Scenario #%d\n", t++); Floyd(); printf("Frog Distance = %.3f\n\n", G[][]); }
return ;
}

dijkstra

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue> using namespace std; #define INF 0xfffffff
#define N 1100
struct node
{
int x, y;
}a[N]; int n, vis[N];
double dist[N], G[N][N]; void Dij()
{
int i, j; for(i=; i<=n; i++)
{
dist[i] = G[][i];
vis[i] = ;
}
vis[] = ; for(i=; i<n; i++)
{
int index=;
double Min=INF;
for(j=; j<=n; j++)
{
if(!vis[j] && dist[j]<Min)
{
Min = dist[j];
index = j;
}
} if(index==)
continue; vis[index] = ; for(j=; j<=n; j++)
if(!vis[j] && max(dist[index], G[index][j])<dist[j])
dist[j] = max(dist[index], G[index][j]);
}
} int main()
{
int iCase = ; while(scanf("%d", &n), n)
{
int i, j; for(i=; i<=n; i++)
scanf("%d%d", &a[i].x, &a[i].y); for(i=; i<=n; i++)
for(j=; j<=i; j++)
{
double d = sqrt( (a[i].x-a[j].x)*(a[i].x-a[j].x) + (a[i].y-a[j].y)*(a[i].y-a[j].y) );
G[i][j] = G[j][i] = d;
} Dij();
printf("Scenario #%d\n", iCase++);
printf("Frog Distance = %.3f\n\n", dist[]);
}
return ;
}

prim

类似于最小生成树

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
const int INF = (<<)-;
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define N 1100 struct node
{
int x, y;
}a[N]; int n, m;
double dist[N], G[N][N];
int vis[N]; double prim()
{
int i, j;
double ans = -; for(i=; i<=n; i++)
dist[i] = G[][i];
dist[] = ; memset(vis, , sizeof(vis));
vis[] = ; for(i=; i<=n; i++)
{
int index = ;
double Min = INF;
for(j=; j<=n; j++)
{
if(!vis[j] && dist[j]<=Min)
{
Min = dist[j];
index = j;
}
} if(index==) break; vis[index] = ; ans = max(ans, Min); if(index==) return ans; for(j=; j<=n; j++)
{
if(!vis[j] && dist[j]>G[index][j])
dist[j] = G[index][j];
}
} return ans;
} int main()
{
int iCase=;
while(scanf("%d", &n), n)
{
int i, j; memset(a, , sizeof(a)); for(i=; i<=n; i++)
scanf("%d%d", &a[i].x, &a[i].y); for(i=; i<=n; i++)
for(j=; j<=i; j++)
G[i][j] = G[j][i] = sqrt( (a[i].x-a[j].x)*(a[i].x-a[j].x) + (a[i].y-a[j].y)*(a[i].y-a[j].y) ); printf("Scenario #%d\n", iCase++);
printf("Frog Distance = %.3f\n\n", prim());
}
return ;
}

(最短路 Floyd diskstra prim)Frogger --POJ--2253的更多相关文章

  1. floyd类型题UVa-10099-The Tourist Guide +Frogger POJ - 2253

    The Tourist Guide Mr. G. works as a tourist guide. His current assignment is to take some tourists f ...

  2. Frogger POJ - 2253(求两个石头之间”所有通路中最长边中“的最小边)

    题意 ​ 题目主要说的是,有两只青蛙,在两个石头上,他们之间也有一些石头,一只青蛙要想到达另一只青蛙所在地方,必须跳在石头上.题目中给出了两只青蛙的初始位置,以及剩余石头的位置,问一只青蛙到达另一只青 ...

  3. Frogger POJ - 2253

    题意 给你n个点,1为起点,2为终点,要求所有1到2所有路径中每条路径上最大值的最小值. 思路 不想打最短路 跑一边最小生成树,再扫一遍1到2的路径,取最大值即可 注意g++要用%f输出!!! 常数巨 ...

  4. kuangbin专题专题四 Frogger POJ - 2253

    题目链接:https://vjudge.net/problem/POJ-2253 思路: 从一号到二号石头的所有路线中,每条路线中都个子选出该路线中两点通路的最长距离,并在这些选出的最长距离选出最短路 ...

  5. Frogger - poj 2253 (Dijkstra)

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28802   Accepted: 9353 Description Fr ...

  6. 最短路(Floyd_Warshall) POJ 2253 Frogger

    题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...

  7. POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)

    POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...

  8. poj 2253 Frogger (最长路中的最短路)

    链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...

  9. POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】

    Frogger Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

随机推荐

  1. Oracle_SQL(2) 分组与聚合函数

    一.聚合函数1.定义:对表或视图的查询时,针对多行记录只返回一个值的函数.2.用途:用于select语句,HAVING条件二.5种聚合函数1.SUM(n) 对列求和 select sum(sal) f ...

  2. eigen Matrix详解

    Eigen Matrix 详解 在Eigen中,所有的matrices 和vectors 都是模板类Matrix 的对象,Vectors 只是一种特殊的矩阵,行或者列为1. Matrix的前三个模板参 ...

  3. linux如何查询系统驱动是否支持该型号显卡

    操作系统在做硬件适配时,经常会检查系统内核是否支持硬件的显卡:如果不支持,则一般是通过升级内核或者该型号对应品牌的显卡驱动来解决(开源或者闭源): 操作流程如下 1> 查询本机的显卡型号 因显卡 ...

  4. ui设计用什么软件

    Ui设计用什么软件?作为ui设计师,你必须要熟练的使用以下几款设计软件,不然可能也无法胜任ui设计师的职位. ui设计除了要学习一些基本的操作软件,如PS AI AE AXURE 以外呢,还要学习比如 ...

  5. nginx 动静分离 以及 负载均衡配置

    测试环境 系统版本:win7 Nginx版本:nginx-1.8.1 Tomcat版本:tomcat-6.0.14 1动静分离配置 Nginx.conf 中 server中 server { list ...

  6. windows中执行celery beat任务

    由于最新的celery4.2不支持windows系统,因此按照网上的建议安装了3.1.25版.按照官网的说明使用 app.conf.beat_schedule = { 'add-every-30-se ...

  7. 2017/2/11CSS基础

    一:html中div: 1.DIV标签应用于 Style Sheet(样式表)方面会更显威力,它最终目的是给设计者另一种组织能力,有 Class.Style.title.ID 等属性. 2.<d ...

  8. MySQL把本地数据库上传到linux

    今天是要导入数据库到linux系统 先用Navicat把sql导出,然后登陆到linux去执行 登陆mysql: mysql -uroot -p123456 创建数据库:create database ...

  9. c#中的as,is和强转

    as和强转之间的区别: as转换类型失败时不会抛出异常:强转类型失败时会抛出异常 引入is先对变量进行检验: if (foo is int) { i = (int)foo; } logger log ...

  10. SQL语句备份和还原数据库

    1,使用SQL最简单备份,还原数据库 1 /* 备份 */ 2 backup database Test to disk='D:/Test.bak' 3 /* 还原 */ 4 restore data ...