题目链接: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. centos7+nginx+rtmp+ffmpeg搭建流媒体服务器

    1.安装前需要的工具 #net-tool 查本地IP #wget 下载安装包 #unzip 解压zip包 #gcc gcc-c++ perl 编译软件包用 yum install -y net-too ...

  2. 7-性能测试i报告

    性能测试报告概述 1.测试报告是指把测试的过程和结果写成文档:对发现的问题和缺陷进行分析:为纠正软件的存在的质量问题提供依据: 为软件验收和交付打下基础 2.性能测试报告属于软件测试报告的一种,主要针 ...

  3. fastcgi 环境变量例子

    例如请求的url http://172.28.250.184:8099/aa.php?var=ccccc&value=bbbbbb 前两个字节分别代表  变量名长度  和 变量值长度. 0x0 ...

  4. service层代码相互调用, 导致spring循环依赖,设计上的优化

    管理员创建用户需要发送激活邮件, 而发送激活邮件的时候需要判断发件人是不是合法的用户, 因此设计到一个循环依赖的问题 //UserService @Service class UserService{ ...

  5. 网上流行的linux内核漫画

  6. 为什么要使用日志管理?syslog和Windows事件日志

    为什么要使用日志管理?syslog和Windows事件日志 日志管理 - 确保网络安全的先决条件 日志给予您有关网络活动的第一手信息.日志管理确保日志中隐藏的网络活动数据转换为有意义的可操作的安全信息 ...

  7. python学习 day6 (3月7日)

    #__author : 'liuyang' #date : 2019/3/7 0007 a = ['a' , 'b' , 'c'] b = [] print(a is b ) # 空元组 可以 空列表 ...

  8. linux_修改ip(重启后永久生效)

    vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet UUID=a20869f2-4095-4e5d-9b0c- ...

  9. kbmmw 中的日期时间操作

    为了精确度反映时间及时区,kbmmw 里面专门有一个单元处理日期时间,由于很多同学习惯了delphi 自带的Tdatetime,使用这个时会有一些疑惑,因此今天就单独说一下这个. 首先kbmmwdat ...

  10. django之补充

    一 QuerySet类型 QuerySet类型:只和orm有关,如果一涉及数据库,就会有QuerySet类型的出现. QuerySet切片操作:QuerySet是支持切片操作的,不过不能放负数.查询集 ...