• poj 2253 一条路径中的最大边 再找出最小的


    题目大意,有两只青蛙,分别在两个石头上,青蛙A想要到青蛙B那儿去,他可以直接跳到B的石头上,也可以跳到其他石头上,再从其他石头跳到B那儿,求青蛙从A到B的所有路径中最小的Frog Distance,我们定义Frog Distance为从A到B的一条路径中最大的一条边
    假如点0到点1有3条路
    第一条路径 会经过2个点 3条边 边的值为 1 4 3
    第二条路径 一条边 5
    第三条路径 1 3 2

    那么 Frog Distance 分别为 4 5 3 则最终输出3

    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 <cstdio>
     3 # include <cstring>
     4 # include <algorithm>
     5 # include <cmath>
     6 # define LL long long
     7 using namespace std ;
     8 
     9 const int MAXN=300;
    10 const double INF=0x3f3f3f3f;
    11 int n ;
    12 bool vis[MAXN];
    13 double cost[MAXN][MAXN] ;
    14 double lowcost[MAXN] ; //保存的是 起点到 i点 所有路径中 最大边中的 最小那条边的权值
    15 
    16 struct point
    17 {
    18     int x ;
    19     int y ;
    20 }p[MAXN];
    21 
    22 void Dijkstra(int beg)
    23 {
    24     for(int i=0;i<n;i++)
    25     {
    26         lowcost[i]=INF;vis[i]=false;
    27     }
    28     lowcost[beg]=0;
    29     for(int j=0;j<n;j++)
    30     {
    31         int k=-1;
    32         double Min=INF;
    33         for(int i=0;i<n;i++)
    34             if(!vis[i]&&lowcost[i]<Min)
    35             {
    36                 Min=lowcost[i];
    37                 k=i;
    38             }
    39             if(k==-1)
    40                 break ;
    41             vis[k]=true;
    42             for(int i=0;i<n;i++)
    43                 if(!vis[i]&&max(lowcost[k],cost[k][i])<lowcost[i])
    44                 {
    45                     lowcost[i]=max(lowcost[k],cost[k][i]);
    46                 }
    47     }
    48 
    49 }
    50 
    51 double dis(point a,point b)
    52 {
    53     return sqrt((double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    54 }
    55 
    56 int main ()
    57 {
    58     //freopen("in.txt","r",stdin) ;
    59     int iCase = 0 ;
    60     while (scanf("%d" , &n ) ,n)
    61     {
    62         iCase++ ;
    63         int u , v , w ;
    64         int i , j ;
    65         for (i = 0 ; i < n ; i++)
    66             scanf("%d %d" , &p[i].x , &p[i].y) ;
    67 
    68         for (i = 0 ; i < n ; i++)
    69         for (j = 0 ; j < n ; j++)
    70        {
    71            if (i == j)
    72               cost[i][j] = 0 ;
    73            else
    74               cost[i][j] = dis(p[i],p[j]) ;
    75        }
    76         Dijkstra(0) ;
    77         printf("Scenario #%d
    Frog Distance = ",iCase);
    78         printf("%.3lf
    
    ",lowcost[1]);
    79 
    80     }
    81 
    82     return 0 ;
    83 }
    View Code
  • 相关阅读:
    单例模式
    json 格式
    axios 获取不到数据错误
    sprint test 添加事务回滚机制
    springboot An incompatible version [1.1.32] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]
    spring boot 启动之后404
    废了
    tomcat 部署项目到服务器
    Druid 介绍及配置
    jq 全选
  • 原文地址:https://www.cnblogs.com/mengchunchen/p/4592216.html
Copyright © 2020-2023  润新知