POJ-2253,Frogger(最短路问题)

简介: POJ-2253,Frogger(最短路问题)

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  


程序代码:


#include<cstdio>
#include<cmath>
#define MAX(x,y)((x)>(y)?(x):(y))
struct point
{
  double x,y;
  bool vis;
};
double distance(point &a,point &b)
{
  return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
point stone[210];
double dist[210][210];
int main()
{
  int n,ans=0;
  while((scanf("%d",&n)!=EOF)&&n)
  {
    for(int i=0;i<n;i++)
    {
      scanf("%lf%lf",&stone[i].x,&stone[i].y);
      stone[i].vis=false;
    }
    for(int i=0;i<n;i++)
    {
      for(int j=0;j<n;j++)
      {
        dist[i][j]=dist[j][i]=distance(stone[i],stone[j]);
      }
    }
    for(int k=0;k<n;k++)
    {
      for(int i=0;i<n;i++)
      {
        for(int j=0;j<n;j++)
        {
          if(dist[i][j]>dist[i][k]&&
            dist[i][j]>dist[j][k])
            dist[i][j]=MAX(dist[i][k],dist[j][k]);
        }
      }
    }
    printf("Scenario #%d\n",++ans);
    printf("Frog Distance = %.3f\n\n",dist[0][1]);
  }
  return 0;
}


相关文章
面试1: 解决线程顺序有几种方式
面试1: 解决线程顺序有几种方式
|
SQL 存储 分布式计算
CDP的Hive3系列之Hive Metastore介绍
CDP的Hive Metastore (HMS) 是一种服务,用于在后端 RDBMS(例如 MySQL 或 PostgreSQL)中存储与 Apache Hive 和其他服务相关的元数据。Impala、Spark、Hive 和其他服务共享元存储。与 HMS 的连接包括 HiveServer、Ranger 和代表 HDFS 的 NameNode。
2629 0
CDP的Hive3系列之Hive Metastore介绍
|
11月前
|
人工智能
人工智能管理体系解读(一)
ISO/IEC 42001 标准旨在指导组织建立、实施、维护和持续改进人工智能管理体系,强调负责任地使用、开发和运营人工智能系统,适用于所有采用AI系统的组织。标准涵盖了道德问题、法律法规遵从性、持续改进等方面,帮助组织提升运营效率、加强风险管理并提高声誉。
229 1
|
存储 安全 生物认证
强密码策略之减少字典攻击风险
【8月更文挑战第14天】
264 2
|
机器学习/深度学习 算法 调度
「AIGC算法」爬山算法详解
**爬山算法是迭代求解优化问题的局部搜索方法,从随机解开始,逐步向邻域内更优解移动,直至达到局部极值。特点包括简单性、可能陷入局部最优和依赖初始解。应用包括调度、路径规划和参数调优。改进策略如随机重启、模拟退火和多起始点可帮助跳出局部最优。主要挑战是局部最优、平坦区域和高维问题。**
553 0
|
小程序
【微信小程序】英文字母不换行问题 flex布局字符超出宽度折行问题:设置了word-break: break-all;和flex: 1;冲突flex不生效问题
【微信小程序】英文字母不换行问题 flex布局字符超出宽度折行问题:设置了word-break: break-all;和flex: 1;冲突flex不生效问题
415 1
|
机器学习/深度学习 数据采集 人工智能
使用R语言进行机器学习的初学者指南
【4月更文挑战第25天】本文是R语言机器学习初学者指南,介绍了R语言在统计分析和机器学习中的应用。首先,简述R语言的背景及特点,包括其丰富的统计功能和扩展性。接着,指导如何安装和配置R语言及RStudio,以及设置国内R包安装源。然后,讲解R语言的基础知识,如数据类型、变量、数据结构和控制结构。此外,文中还推荐了几个常用的机器学习库,如caret、gbm、RandomForest和xgboost。最后,通过一个线性回归模型实例,展示了使用R语言进行机器学习的基本流程,包括数据准备、预处理、模型训练、评估和预测。
445 2
|
机器学习/深度学习 JSON 数据挖掘
使用Python调用API接口获取淘宝商品数据
本文介绍了如何使用Python调用API接口获取淘宝商品数据。通过调用淘宝开放平台的API接口,我们可以获取到淘宝商品的详细信息,包括商品名称、价格、销量等。这些数据可以用于进行各种分析,例如商品的价格趋势、销量趋势等。通过Python的强大功能,我们可以更方便地获取和处理这些数据,从而更好地理解淘宝的商品市场。
|
安全 数据安全/隐私保护 物联网
带你读《自主管理身份:分布式数字身份和可验证凭证》——第3章 用示例场景演示SSI工作原理(1)
带你读《自主管理身份:分布式数字身份和可验证凭证》——第3章 用示例场景演示SSI工作原理(1)
带你读《自主管理身份:分布式数字身份和可验证凭证》——第3章 用示例场景演示SSI工作原理(1)
数据结构学习笔记——顺序存储结构实现循环队列
数据结构学习笔记——顺序存储结构实现循环队列
数据结构学习笔记——顺序存储结构实现循环队列