• Forgger


    2017-08-08

    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

    题目大意 :有两只青蛙,其中一只想要去拜访另一只青蛙。但它有点懒,不想一步跳的太远,它宁愿一步跳少点,多跳几次。问青蛙在这个过程中,跳的最小的一步是多少。

    题目分析 :怎么说呢?一开始想用krusual算法去做,但想着之前做了那么多的最小生成树,这次换一种算法吧!结果,另一种算法不熟悉,弄得我生不如死啊!我是用Dijkstra算法做的。

    不过也不算Dijkstra算法吧,算是一种变形,不过这种变形,有点不太像它本身的作用了。
        
    思 路 :1.从起点开始,我们得到该点到到任意点的距离,取最短。---> 2.用一个数ans将这个距离保存起来,如果还有比它小的数则替换掉。---> 3.松弛操作:改变接下来保存距离数

    的大小 ---> 循环前面几步,知道走到终点即可。

    题目收获 : 每一次求最短的有效方法。

    void Dijkstra()
    {
        for(int i = 1; i <= n; i++) d[i] = DNF;//每个值全为无穷。
        d[1] = 0;//起始点为0;
        memset(vis,0,sizeof(vis));
    
        for(int i = 1; i <= n; i++)
        {
            //cout << "***********************" << "
    " <<endl;
            int x;
            double m = DNF;
            for(int y = 1; y <= n; y++)//求最小的权;
                 if(!vis[y] && d[y] <= m)
                       m = d[x=y];
            //cout << "X:" << x << endl;
            vis[x] = 1;
            if(ans < d[x] && d[x]!= DNF)
            {
                ans = d[x];//记录最小权,每次替换。
                //printf("DNS:%f
    ",ans);
            }
            if(x == 2) 
                return;
            for(int y = 1; y <= n; y++)
                if(!vis[y])
            {
                d[y] = min(d[y], w[x][y]);//松弛操作。得到当前驱节点到下一任意节点的距离。
            }
    
        }
    
    }            

          
  • 相关阅读:
    myeclipse tomcat启动,内存溢出问题
    SQL Server 中的模糊查询 LIKE
    GridView学习
    自己手动创建dataset的方法(不用从数据库倒入)
    关于在updatepanel中response失效的解决方法
    CSS中背景图片定位方法
    Visual Studio 2005中调试SQL Server 2005的存储过程
    第二个dropdownlist不能触发selectchange的问题
    C/C++ 控制台窗口暂停
    蛇形矩阵
  • 原文地址:https://www.cnblogs.com/7750-13/p/7308909.html
Copyright © 2020-2023  润新知