Frog

Description
There is a named Freddy frog sitting on a stone on the center of the lake, and suddenly he found another frog (her name is Fiona) sitting on a stone on another. He wants to find her past, but because of dirty water, everywhere is full of tourists sunscreen, so he decided to jump, rather than using travel.
Ominously Fiona stone from his distance he could jump beyond the scope. So Freddy consider using some other stones as a relay station, so he can jump relatively small distance (perhaps to jump many times) to find Fiona.
To jump like this in a row, it is clear once Freddy can jump distance must be at least distance and the greatest distance between the string of stone. Thus the path, the distance between the stones between leapfrog (frog distance, also known as human minmax distance) is defined as where Freddy stone to jump from stone Fiona located, the minimum distance necessary to jump.
To stone you where Freddy, stone Fiona located, as well as coordinate all other stones in the lake, your task is to calculate the distance between leapfrog between Freddy and stone Fiona lies.
Input
Input contains multiple test data. The first column of each test data has an integer n, represents the number of stones (2 <= n <= 200 ). The next n columns each column has two integers xi, yi (0 <= xi , yi <= 1000) representative of the coordinates of the i-th marbles. Wherein the first one is located Freddy stone, stone Fiona second teeth is located on the other n-2 pieces of stone is empty.
After each test a blank column represents 0 when n = input end. Refer to the Sample Input.
Output
for each set of test data, which is an output of several groups of test data, and a leapfrog distance.
Also a blank column in each group after the output test data. Refer to the Sample Output.
The Input the Sample
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

sol:

Summed up the problem: find a starting point to the maximum weight on the side of the end point of the path of least, the output value. Below, a starting point, the end point of a plurality of paths from 5.1 to 5, but the maximum on the right side of this path is 1-3-2-1 6, is the smallest in all paths.

Solution: First press the right side after the big hit since childhood, the sort order plus side, into a collection, each adding an edge to determine whether the start and end points in a set. If in, it indicates the start and end points have been communicated, the current value of the right side of the answer. As shown above, before adding 2-5, the right side is 1, plus 1-3, the right side is three, plus 2-3, the right side is 4, plus 1-3, the right side is 6, the starting point at this time 5 has an end in communication with, the case 6 is the answer.

code show as below:

#include<bits/stdc++.h>
using namespace std;
int n,c,qaq;
double a[2010],b[2010],ans;
struct kkk{
    int x,y;double v;
}bb[1000000];int tot;
bool cmp(kkk a,kkk b)
{return a.v<b.v;}
int fa[2010];
int get(int x){return fa[x]==x?fa[x]:fa[x]=get(fa[x]);}
double turn(int x,int y) 
{
    double dx = a[x] - a[y];
    double dy = b[x] - b[y];
    return sqrt(dx * dx + dy * dy);
}
int main()
{
    while(1)
    {
        ++qaq;
        scanf("%d",&n);
        if(n==0) break;
        tot=0;
        for(int i=1;i<=n;i++)
        fa[i]=i;
        for(int i=1;i<=n;i++)
        scanf("%lf %lf",&a[i],&b[i]);
     
        for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            bb[++tot].x=i,bb[tot].y=j,bb[tot].v=turn(i,j);
   
        sort(bb+1,bb+tot+1,cmp);
    
        for(int i=1;i<=tot;i++)
            if(get(bb[i].x)!=get(bb[i].y))
            {
                fa[get(bb[i].x)]=get(bb[i].y);
                if(get(1)==get(2))
                {
                    ans=bb[i].v;
                    break;
                }
            }
        printf("Scenario #%d\nFrog Distance = %.3lf\n\n",qaq,ans);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/cutepota/p/12510287.html