POJ 2253-frogger (maximum weight of the minimum spanning tree)

Source: Internet
Author: User

Original title Link: Click here

Test instructions

a frog, named Freddy, crouched on a stone in the lake. Suddenly he found a frog named Fiona on another stone in the lake. Freddy want to date with Fiona, but because the lake is too dirty, he did not want to swim in the past, but jumped over to find Fiona. Unfortunately, Fiona's Stone was a bit far from him, even beyond his ability to jump. However, Freddy noticed that there were some other stones in the lake. These stones may turn this long jumping distance into a few short jumping distances. We define "frog distance" as the longest of several jumps needed for Freddy to jump to Fiona. Now give you freddy,fiona, and the coordinates of other stones in the lake, so that you find the shortest "frog distance." The input may be multiple sets of test data. The first row of each set of data has an integer n (2<=n<= $), which indicates how many stones there are in the lake. The next n rows, each line has two integers xi,yi (0<= Xi,yi <= +), which represents the coordinates of the block I stone. The coordinates of the 1th stone are the position of the Freddy, the coordinates of the second stone are the position of the Fiona, and there are no frogs on the other stones. When the input n=At 0, the program ends. For each set of test data, first output one row"Scenario #x", and then output in the next line"Frog Distance = y"。 where x indicates the current set of test data, Y is the minimum "frog distance" for the set of data. Output a blank line between each of the two sets of test data.
View Code

It seems that the topic for a long time did not understand what it was, and then learned to get things to the minimum spanning tree maximum power. So let's use the Dijkstra algorithm !

#include <iostream>#include<string.h>#include<stdio.h>#include<algorithm>#include<Set>#include<queue>#include<map>#include<vector>#include<string>#include<math.h>using namespacestd;Const intmaxn= About;p Air<int,int>P[MAXN];DoubleD[MAXN][MAXN];DoubleDis (pair<int,int>p1,pair<int,int>p2) {    returnsqrt ((Double) (P1.first-p2.first) * (P1.first-p2.first) + (p2.second-p1.second) * (p2.second-p1.second));}intMain () {intN,x,y; intflag=0;  while(SCANF ("%d", &n) &&N) {flag++; printf ("Scenario #%d\n", flag);  for(intI=0; i<n;i++) {scanf ("%d%d",&x,&y); P[i]=Make_pair (x, y); }         for(intI=0; i<n;i++)             for(intj=0; j<n;j++) {D[j][i]=d[i][j]=dis (p[i],p[j]); }         for(intk=0; k<n;k++)             for(intI=0; i<n;i++)                 for(intj=0; j<n;j++)                    if(d[i][j]>Max (D[i][k],d[k][j]) d[i][j]=Max (d[i][k],d[k][j]); printf ("Frog Distance =%.3f\n\n", d[0][1]); }    return 0;}
View Code

POJ 2253-frogger (maximum weight of the minimum spanning tree)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.