zoukankan      html  css  js  c++  java
  • poj 2253 Frogger(dijkstra)

    Frogger
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 20262   Accepted: 6575

    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<iostream>
     2 #include<string.h>
     3 #include<stdio.h>
     4 #include<math.h>
     5 #define INF 999999999
     6 using namespace std;
     7 double distance(int x1,int y1,int x2,int y2){return sqrt((double)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));}
     8 double map[222][222],dis[222];
     9 int xx[222],yy[222],v[222];
    10 
    11 double max(double a,double b){return a<b?b:a;}
    12 double min(double a,double b){return a>b?b:a;}
    13 
    14 void dijkstra(int s,int n)
    15 {
    16     int i,j,k;
    17     for(i=1;i<=n;i++)
    18     {
    19         dis[i]=map[s][i];
    20     }
    21     memset(v,0,sizeof(v));
    22     v[1]=1;
    23     for(i=2;i<=n;i++)
    24     {
    25         k=1;
    26         double maks=INF;
    27         for(j=1;j<=n;j++)
    28         {
    29             if(!v[j]&&dis[j]<maks)
    30             {
    31                 maks=dis[j];
    32                 k=j;
    33             }
    34         }
    35         v[k]=1;
    36         for(j=1;j<=n;j++)
    37         {
    38             if(!v[j])
    39             {
    40                 dis[j]=min(dis[j],max(dis[k],map[k][j]));  //主要更新地方
    41             }
    42         }
    43     }
    44 }
    45 
    46 int main()
    47 {
    48     int n,k=1;
    49     while(~scanf("%d",&n)&&n)
    50     {
    51         int i,x,y,j;
    52         for(i=1;i<=n;i++)
    53         {
    54             scanf("%d%d",&x,&y);
    55             xx[i]=x;
    56             yy[i]=y;
    57         }
    58         for(i=1;i<n;i++)
    59         {
    60             map[i][i]=0;
    61             for(j=i+1;j<=n;j++)
    62             {
    63                 map[j][i]=map[i][j]=distance(xx[i],yy[i],xx[j],yy[j]);
    64             }
    65         }
    66         dijkstra(1,n);
    67         printf("Scenario #%d\nFrog Distance = %.3lf\n\n",k++,dis[2]);
    68     }
    69     return 0;
    70 }
  • 相关阅读:
    服务器控件Repeater
    HeidiSQL无法连接Myql
    未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序搜索
    DISTINCT删除重复数据
    Makedown文件保存问题
    Makedown 本地图片问题
    vsftpd配置文件详解[转载]
    centos 本地yum源的搭建
    OpenOffice菜单乱码解决和linux下安装字体
    让secureCRT正确显示中文
  • 原文地址:https://www.cnblogs.com/crazyapple/p/3111618.html
Copyright © 2011-2022 走看看