FOGGER(洛谷)

FreddyFrogissittingonastoneinthemiddleofalake. SuddenlyhenoticesFionaFrogwhoissitting onanotherstone.Heplanstovisither,butsincethewater isdirtyandfulloftourists’ sunscreen,he wantstoavoidswimmingandinsteadreachherbyjumping. UnfortunatelyFiona’sstoneisoutofhisjumprange.ThereforeFreddyconsiderstouseotherstones asintermediatestopsandreachherbyasequenceofseveralsmall jumps. Toexecuteagivensequenceofjumps,afrog’sjumprangeobviouslymustbeatleastaslongasthe longestjumpoccuringinthesequence. Thefrogdistance(humansalsocall itminimaxdistance)betweentwostonesthereforeisdefinedas theminimumnecessaryjumprangeoverallpossiblepathsbetweenthetwostones. YouaregiventhecoordinatesofFreddy’sstone,Fiona’sstoneandallotherstonesinthelake.Your jobistocomputethefrogdistancebetweenFreddy’sandFiona’sstone. Input The inputfilewill containoneormore test cases. Thefirst lineof eachtest casewill containthe numberofstonesn(2≤n≤200).Thenextnlineseachcontaintwointegersxi,yi (0≤xi,yi≤1000) representingthecoordinatesof stone#i. Stone#1isFreddy’sstone, stone#2isFiona’sstone, the othern−2stonesareunoccupied. There’sablanklinefollowingeachtestcase. Input isterminated byavalueofzero(0)forn. Output Foreachtestcase,printalinesaying‘Scenario #x’andalinesaying‘Frog Distance = y’wherex isreplacedbythetestcasenumber(theyarenumberedfrom1)andy isreplacedbytheappropriate realnumber,printedtothreedecimals.Putablanklineaftereachtestcase,evenafterthelastone. SampleInput 2 00 34 3 174 194 185 0 SampleOutput Scenario#1 FrogDistance= 5.000 Scenario#2 FrogDistance= 1.414

一只叫 Freddy 的青蛙蹲坐在湖中的一块石头上,突然他发现一只叫 Fiona 的青蛙在湖中的另一块石头上。

Freddy 想要跟 Fiona 约会,但由于湖水太脏,他不想游泳过去而是跳过去找 Fiona。很不幸,Fiona 所在的石头距离他有点远,甚至超出了他的跳跃能力。然而 Freddy 注意到湖中还有一些其他的石头。这些石头也许会将这个很长的跳跃距离化成若干个短的跳跃距离。我们定义“青蛙距离”为 Freddy 跳到 Fiona 那里所需要的若干次跳跃中最长的那一次。

现在给你 Freddy,Fiona,以及湖中其他石头的坐标,让你求出最短的“青蛙距离”。

输入格式

本题有多组数据

每组数据的第一行有一个整数 �n,表示湖中一共有多少块石头。

接下来的 �n 行,每一行有两个整数 ��,��xi​,yi​,表示第 �i 块石头的坐标。第 11 块石头的坐标是 Freddy 所在的位置,第 22 块石头的坐标是 Fiona 所在的位置,其他的石头上都没有青蛙。

当输入 �=0n=0 的时候,程序结束。

保证 2≤�≤2002≤n≤200,0≤��,��≤1030≤xi​,yi​≤103。

输出格式

对于每一组测试数据,先输出一行 Scenario #x,然后在下一行输出 Frog Distance = y

其中 x 表示当前是第几组测试数据,y 为该组数据的最小“青蛙距离”。

每两组测试数据之间输出一个空行。

输入输出样例

输入 #1复制

2
0 0
3 4

3
17 4
19 4
18 5
0

输出 #1复制

Scenario #1
Frog Distance = 5.000

Scenario #2
Frog Distance = 1.414
#include <bits/stdc++.h>
using namespace std;
double w[1000][1000];
int n,t=1;
struct u{
    int x,y;
}a[1000];
void floyd(){
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                w[i][j]=min(w[i][j],max(w[i][k],w[k][j]));
}
double d(int q,int p,int u,int y){
    return sqrt(pow((q-u),2)+pow((p-y),2));
}
int main(){
    while(cin>>n){
        memset(w,0x3f,sizeof(w));
        if(n==0)return 0;
        for(int i=1;i<=n;i++){
            cin>>a[i].x>>a[i].y;
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                w[i][j]=d(a[i].x,a[i].y,a[j].x,a[j].y);
            }
        }
        floyd();
        cout<<"Scenario #"<<t<<endl;
        cout<<"Frog Distance = ";
        cout<<fixed<<setprecision(3)<<w[1][2]<<endl;
        t++;
    }
} 
  • 16
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值