zoukankan      html  css  js  c++  java
  • Frogger

    Frogger

    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

    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

    //终于看懂了这题,第一行说明有n个石头(2<=n<=200 )然后 n 行,第一行是起点坐标,第二行是终点坐标,要求跳跃的距离尽量小,直到到达终点,输出最大的一次跳跃距离,输出格式有点坑

    //用floyed做比较简单,mp[i][j] 存 i 到 j 的最大距离的最小值,三重循环

    floyd算法 32ms
     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <math.h>
     5 using namespace std;
     6 #define MX 205
     7 struct Node
     8 {
     9     double x,y;
    10 }node[MX];
    11 int n;
    12 double mp[MX][MX];
    13 
    14 int main()
    15 {
    16     int cas = 1;
    17     while (scanf("%d",&n)&&n)
    18     {
    19         for (int i=0;i<n;i++)
    20         {
    21             scanf("%lf%lf",&node[i].x,&node[i].y);
    22             for (int j=i;j>=0;j--)
    23             {
    24                 double dis = sqrt((node[i].x-node[j].x)*(node[i].x-node[j].x)+(node[i].y-node[j].y)*(node[i].y-node[j].y));
    25                 mp[i][j]=mp[j][i]=dis;
    26             }
    27         }
    28         for (int k=0;k<n;k++)
    29         {
    30             for (int i=0;i<n;i++)
    31             {
    32                 for (int j=0;j<n;j++)
    33                 {
    34                     double mmm = max(mp[i][k],mp[k][j]);
    35                     if (mmm<mp[i][j]) mp[j][i]=mp[i][j] = mmm;
    36                 }
    37             }
    38         }
    39         printf("Scenario #%d
    ",cas++);
    40         printf("Frog Distance = %.3f
    
    ",mp[0][1]);
    41     }
    42     return 0;
    43 }
    View Code

    二分+Dijkstra 16ms

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <math.h>
     5 using namespace std;
     6 #define eps 1e-8
     7 #define INF 0x3fffffff
     8 #define MX 205
     9 struct Node
    10 {
    11     double x,y;
    12 }node[MX];
    13 int n;
    14 double mp[MX][MX];
    15 double dis[MX]; //dis[i] 代表去 i 点的最小距离
    16 int vis[MX];
    17 
    18 double dij(double x)//在这个限制下跑dij
    19 {
    20     memset(vis,0,sizeof(vis));
    21     for (int i=0;i<n;i++) dis[i]=INF;
    22     dis[0]=0;
    23     for (int i=0;i<n;i++)
    24     {
    25         double mmm = INF;
    26         int mmxx;
    27         for (int j=0;j<n;j++)
    28         {
    29             if (!vis[j]&&dis[j]<x&&dis[j]<mmm)
    30             {
    31                 mmm=dis[j];
    32                 mmxx = j;
    33             }
    34         }
    35         if (mmm==INF) break;
    36         vis[mmxx]=1;
    37         for (int j=0;j<n;j++)
    38         {
    39             if (!vis[j]&&mp[mmxx][j]<dis[j])
    40                 dis[j] = mp[mmxx][j];
    41         }
    42         if (dis[1]<x) return 1;
    43     }
    44     return 0;
    45 }
    46 
    47 int main()
    48 {
    49     int cas = 1;
    50     while (scanf("%d",&n)&&n)
    51     {
    52         for (int i=0;i<n;i++)
    53         {
    54             scanf("%lf%lf",&node[i].x,&node[i].y);
    55             for (int j=i;j>=0;j--)
    56             {
    57                 double dis = sqrt((node[i].x-node[j].x)*(node[i].x-node[j].x)+(node[i].y-node[j].y)*(node[i].y-node[j].y));
    58                 mp[i][j]=mp[j][i]=dis;
    59             }
    60         }
    61         double left = 0,right = 2000;
    62         while (right-left>eps)
    63         {
    64             double mid = (left+right)/2;
    65             if (dij(mid)) right = mid;
    66             else left = mid;
    67         }
    68         printf("Scenario #%d
    ",cas++);
    69         printf("Frog Distance = %.3f
    
    ",left);
    70     }
    71     return 0;
    72 }
    View Code
     
     
     
  • 相关阅读:
    基于TensorRT的BERT实时自然语言理解(下)
    基于TensorRT的BERT实时自然语言理解(上)
    lsof
    kata-runtime spec
    kata 虚拟机
    json + jq命令
    kata-runtime run mycontainer
    kata-runtime来运行容器
    docker + docker-runc
    kata container在aarch64上成功运行
  • 原文地址:https://www.cnblogs.com/haoabcd2010/p/5709809.html
Copyright © 2011-2022 走看看