• poj 2253 Frogger


                                                                                     Frogger
     
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 21783   Accepted: 7091

    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

     -----------------------------   

      此题对我来说真是头痛啊,本就不怎懂题意,,,还搞得这么深奥,擦。。。。。其实就是在最短路中求最大值!!!

     1  #include<stdio.h>
     2  #include<string.h> 
     3  #include<math.h>
     4  
     5  #define N 202
     6  #define INF 9999999.9 
     7  
     8  struct node
     9  {
    10      double x,y; 
    11  }cord[N]; 
    12  double map[N][N],dis[N]; 
    13  int vist[N],n; 
    14  void init()
    15 {
    16     for(int i=1;i<=n;i++)
    17     for(int j=1;j<=n;j++)
    18     map[i][j]=INF; 
    19 }
    20  void ping(int x,int y)
    21  {
    22      map[x][y]=sqrt((cord[x].x-cord[y].x)*(cord[x].x-cord[y].x)+(cord[x].y-cord[y].y)*(cord[x].y-cord[y].y)); 
    23  } 
    24  double kij()
    25  {
    26      int i,j,k; 
    27      memset(vist,0,sizeof(vist));
    28      for(i=1;i<=n;i++)dis[i]=map[1][i];  
    29     double min=0; 
    30     for(i=1;i<=n;i++)  
    31     {  
    32         double max=INF;
    33         for(j=2;j<=n;j++)
    34         if(!vist[j]&&dis[j]<max)
    35         {
    36           max=dis[j];
    37           k=j; 
    38         } 
    39         vist[k]=1;
    40         if(max>min){min=max;}
    41         if(k==2)break; 
    42         for(j=2;j<=n;j++)
    43             if(!vist[j]&&map[k][j]<dis[j])
    44                 dis[j]=map[k][j]; 
    45     }
    46     return min;     
    47  } 
    48  int main ()
    49  {
    50      int ca=1,i,j; 
    51      while(scanf("%d",&n)!=EOF&&n)
    52      {
    53          init(); 
    54         for(i=1;i<=n;i++)
    55          scanf("%lf%lf",&cord[i].x,&cord[i].y);     
    56         for(i=1;i<=n;i++)
    57         for(j=1;j<=n;j++)
    58         if(i!=j) ping(i,j); 
    59         printf("Scenario #%d
    ",ca++); 
    60         printf("Frog Distance = %.3lf
    
    ",kij()); 
    61      } 
    62  } 
  • 相关阅读:
    这是一篇通过open live writer发布的博文
    网卡重启失败
    2020年1月目标
    二、安装docker
    JS中的数据类型,包含ES6,set和map等等
    关于prototype和__proto__,最好的一些解释
    JS中call,apply和bind方法的区别和使用场景
    ThinkPHP5生成word文档代码库
    js/jquery操作iframe
    PHP技术--思维导图
  • 原文地址:https://www.cnblogs.com/ace-top/p/3289713.html
Copyright © 2020-2023  润新知