博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Frogger
阅读量:6155 次
发布时间:2019-06-21

本文共 2531 字,大约阅读时间需要 8 分钟。

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

20 03 4317 419 418 50

Sample Output

Scenario #1Frog Distance = 5.000Scenario #2Frog Distance = 1.414

Hint

#include <iostream>

#include <iomanip>
#include <cmath>
using namespace std;
class point
{public:
int x,y;}p[201];
double pa[201][201];
int main()
{
int t=1,n;
while(cin>>n,n!=0)
{int i,j,k;
for(i=1;i<=n;i++)
cin>>p[i].x>>p[i].y;
for(i=1;i<=n-1;i++)
for(j=i+1;j<=n;j++)
{

double x1=p[i].x-p[j].x; 

 double y1=p[i].y-p[j].y; 
pa[i][j]=pa[j][i]=sqrt(x1*x1+y1*y1);

}

 

for(k=1;k<=n;k++)

for(i=1;i<=n-1;i++)
for(j=i+1;j<=n;j++)
{
if(pa[i][k]<pa[i][j] && pa[k][j]<pa[i][j])    
                        if(pa[i][k]<pa[k][j])           
                            pa[i][j]=pa[j][i]=pa[k][j]; 
                        else 
                            pa[i][j]=pa[j][i]=pa[i][k]; 

}

cout<<"Scenario #"<<t++<<endl; 

cout<<fixed<<setprecision(3)<<"Frog Distance = "<<pa[1][2]<<endl<<endl; 

}

 

return 0;}

转载于:https://www.cnblogs.com/lengxia/p/4387799.html

你可能感兴趣的文章
Windows phone 8 学习笔记(3) 通信
查看>>
Revit API找到风管穿过的墙(当前文档和链接文档)
查看>>
Scroll Depth – 衡量页面滚动的 Google 分析插件
查看>>
Windows 8.1 应用再出发 - 视图状态的更新
查看>>
自己制作交叉编译工具链
查看>>
Qt Style Sheet实践(四):行文本编辑框QLineEdit及自动补全
查看>>
[物理学与PDEs]第3章习题1 只有一个非零分量的磁场
查看>>
深入浅出NodeJS——数据通信,NET模块运行机制
查看>>
onInterceptTouchEvent和onTouchEvent调用时序
查看>>
android防止内存溢出浅析
查看>>
4.3.3版本之引擎bug
查看>>
SQL Server表分区详解
查看>>
使用FMDB最新v2.3版本教程
查看>>
STM32启动过程--启动文件--分析
查看>>
垂死挣扎还是涅槃重生 -- Delphi XE5 公布会归来感想
查看>>
淘宝的几个架构图
查看>>
linux后台运行程序
查看>>
Python异步IO --- 轻松管理10k+并发连接
查看>>
Oracle中drop user和drop user cascade的区别
查看>>
登记申请汇总
查看>>