• POJ 2253 Frogger


    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上,它想要拜访在石头2上的青蛙,但是他的弹跳能力有限,可能这两个石头离得很远,所以它可以借助其他的石头来帮助自己,那么现在求它至少能跳多远才能去拜访另一只青蛙,即求两点之间所有路径之间最大值的最小值最短路问题有很多都是求最大值中的最小值或者是最小值中的最大值,原理差不多的~~~~)
    #include<stdio.h>
    #include<math.h>
    #define INF 0x3f3f3f3f
    #define N 210
    #define max(a, b) (a > b ? a : b)
    double G[N][N], dist[N]; //dist数组存放的是两点之间所有路径之间最大距离的最小值的平方(两点间的距离计算时最好用平方,结果别忘了开方就行)
    int visit[N], n;
    void Init()
    {
        int i;
        for (i = 0; i <= n; i++)
        {
            dist[i] = INF;
            visit[i] = 0;
        }
    }
    void Dist()
    {
        int i, j, idex;
        double Min;
        dist[1] = 0;
        for (i = 1; i <= n; i++)
        {
            Min = INF;
            for (j = 1; j <= n; j++)
            {
                if (!visit[j] && dist[j] < Min)
                {
                    Min = dist[j];
                    idex = j;
                }
            } //第一个for循环是为了标记每一个已经确定的dist值,若n个都确定好了就可以结束了
            visit[idex] = 1;
            for (j = 1; j <= n; j++)
            {
                if (!visit[j] && dist[j] > max(dist[idex], G[idex][j]))
                    dist[j] = max(dist[idex], G[idex][j]);
            } //第二个for循环是为了给dist数组存入数据
        }
    }
    int main ()
    {
        double a[N], b[N];
        int k = 0, i, j;
        while (scanf("%d", &n), n)
        {
            Init();
            k++;
            for (i = 1; i <= n; i++)
                scanf("%lf %lf", &a[i], &b[i]);
            for (i = 1; i <= n; i++)
            {
                for (j = 1; j <= n; j++)
                    G[i][j] = (a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]);
            }
            Dist();
            printf("Scenario #%d
    ", k);
            printf("Frog Distance = %.3lf
    ", sqrt(dist[2]));
            printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    day15-collection和其子类
    day14-正则表达式和常用类
    day13-StringBuffer和数组高级,Arrays
    day12-Scanner和String
    day11-object
    linux进程(一)
    CentOS6与CentOS7的启动过程
    linux特殊权限(acl)
    linux系统权限(基本权限)
    linux系统用户管理(二)
  • 原文地址:https://www.cnblogs.com/syhandll/p/4678278.html
Copyright © 2020-2023  润新知