• Frogger(floyd变形)


    Frogger
    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

    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.
     
    这道题的题意不好懂。。。
    重点理解下面一段:
    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. 
    由1到2存在路经p1,p2,...,pm。路径pi中的“longest jump”为di,则最终答案为min(d1,d2,...,dm)
    AC Code:
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <deque>
     4 #include <cstdio>
     5 #include <cstring>
     6 #include <cmath>
     7 
     8 using namespace std;
     9 
    10 const int sz = 201;
    11 const double inf = 10.0e8;
    12 double d[sz][sz], x[sz], y[sz];
    13 int n;
    14 
    15 void get_dist(int i, int j)
    16 {
    17     d[i][j] = d[j][i] = sqrt((x[i] - x[j]) * (x[i] - x[j]) +
    18                                    (y[i] - y[j]) * (y[i] - y[j]));
    19 }
    20 
    21 void floyd()
    22 {
    23     for(int k = 1; k <= n; k++){
    24         for(int i = 1; i <= n; i++){
    25             for(int j = 1; j <= n; j++){
    26                 d[i][j] = min(d[i][j], max(d[i][k], d[k][j]));
    27             }
    28         }
    29     }
    30 }
    31 
    32 int main()
    33 {
    34     int ca = 1;
    35     while(scanf("%d", &n) && n){
    36         for(int i = 1; i <= n; i++){
    37             for(int j = 1; j <= n; j++){
    38                 d[i][j] = inf;
    39             }
    40             d[i][i] = 0.0;
    41         }
    42         for(int i = 1; i <= n; i++){
    43             scanf("%lf %lf", x + i, y + i);
    44             for(int j = i - 1; j > 0; j--){
    45                 get_dist(i, j);
    46             }
    47         }
    48         floyd();
    49         printf("Scenario #%d
    Frog Distance = %.3lf
    
    ", ca++, d[1][2]);
    50     }
    51     return 0;
    52 }
     
  • 相关阅读:
    6.数字三角形
    5.分组背包问题
    1.商品模块表结构分析
    AUTH_USER_MODEL refers to model 'user.User' that has not been installed
    发布品论接口
    查询指定课程评论接口
    1.评论模块表结构
    上传视频课程到七牛云后存储到django后端接口
    5.上传视频到七牛云django端实现
    4.七牛云上传前台页面
  • 原文地址:https://www.cnblogs.com/cszlg/p/3304813.html
Copyright © 2020-2023  润新知