Frogger POJ - 2253 (seeking between two stones "all sides of the longest path in the" edge minimum)

The meaning of problems

Subject mainly to say is that there are two frogs, two in stone, there are some stones between them, a frog in order to reach the place where another frog, have to jump on the stone. It gives the title frog two initial position, and the remaining stone, a frog asked to reach all the other paths in the location frog " The Frog Distance minimum value" is.

Explain " at The Frog Distance ": the title gives some explanation " at The Frog Distance (humans Also Minimax Distance Call IT) defined the BETWEEN TWO AS IS THEREFORE Stones at The Minimum Necessary Jump the Range over All Possible Paths the BETWEEN TWO at The Stones." wherein the jump range actually refers to the largest side of a path in front of the word minimum on the requirements for the minimum of all the maximum passage of the side edge. If direct say in front of this sentence you might feel more around, after the adoption of the above explanation I think you should get the idea.

Through the above analysis, not difficult to see the purpose of this question is to find the smallest of all sides in the path of the largest side, you can use floyd, Dijkstra algorithm to solve the problem, pay attention to this question is no place you find between two points the shortest, only uses some algorithms thinking of them. Of course, to solve this problem requires a particularly important equation,

d[j] = min(d[j], max(d[x], dist[x][j]));        //dis[j]为从一号石头到第j号石头所有通路中最长边中的最小边

AC Code

Use Dijkstra's algorithm :

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
const int maxn = 200 + 10;
const int inf = 0x3f3f3f3f;
int x[maxn], y[maxn], vis[maxn];
double dist[maxn][maxn], d[maxn];
double solve()
{
    memset(vis, 0, sizeof(vis));
    for(int i = 1;i <= n; i++)
        d[i] = dist[i][1];
    for(int i = 1; i <= n; i++)
    {
        int x;
        double minn = inf;
        for(int j = 1; j <= n; j++)
        {
            if(!vis[j] && d[j] < minn)
            {
                x = j;
                minn = d[j];
            }
        }
        vis[x] = 1;
        for(int j = 1; j <= n; j++)
            d[j] = min(d[j], max(d[x], dist[x][j]));        //dis[j]为从一号石头到第j号石头所有通路中最长边中的最小边
    }
    return d[2];
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int cnt = 0;
    while(scanf("%d", &n) && n)
    {
        for(int i = 1; i <= n; i++)
            scanf("%d %d", &x[i], &y[i]);
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                if(i == j)
                    dist[i][j] = 0;
                else
                    dist[i][j] = sqrt(double(x[i] - x[j])*(x[i] - x[j]) + double(y[i] - y[j])*(y[i] - y[j]));
            }
        }
        printf("Scenario #%d\n", ++cnt);
        printf("Frog Distance = ");
        printf("%.3lf\n\n",solve());
    }
}

Guess you like

Origin www.cnblogs.com/KeepZ/p/12199322.html