POJ 2253 Frogger

Source: Internet
Author: User

Topic Links:

poj.org/problem?id=2253

Main topic:

Freddy Frog sat on a stone in the lake, and suddenly he noticed Fiona Frog sitting on another rock, Freddy Frog to visit Fiona Frog, but the water was dirty, and there was a visitor's sunscreen floating above, in order to avoid swimming in the past he can only jump over.

Unfortunately, Fiona's stone is not within the range of his jump, so he can only jump a few other stones to reach the stone where Fiona, the frog's jump has a great distance and a very small distance, obviously on his way to jump, the longest distance can not exceed his jumping limit.

Give you the coordinates of all the stones in the lake, and your task is to calculate the distance of the stones of two people.

Input:

The first line of an n represents the number of stones, the first stone Freddy position, the second stone Fiona position, the rest of the n-2 stone is empty, give you the coordinates of each point, the request is to find a path, you beg this way of the two stones the longest distance, in all the shortest path.

Topic Analysis:

This problem is in fact the shortest to seek the largest side, has done this kind of topic before. Using SPFA, I wrote it directly.

Note: please use C + + g++ when submitting.

#include <iostream>#include<cstdlib>#include<cstdio>#include<algorithm>#include<vector>#include<queue>#include<cstring>#include<cmath>using namespacestd;#defineINF 0XFFFFFFF#defineMAXN 300structpoint{Doublex, y;};DoubleLen (Point A, point B) {returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y));}intN;DoubleDIST[MAXN];DoubleG[MAXN][MAXN];BOOLVIS[MAXN];DoubleSPFA () {intP =1; Queue<int>Q;    Q.push (P);  while( !Q.empty ()) {P=Q.front ();        Q.pop (); VIS[P]=false;  for(intI=1; i<=n; i++)        {            if(Dist[i] >Max (Dist[p],g[p][i])) {Dist[i]=Max (dist[p],g[p][i]); if( !Vis[i]) {Vis[i]=true;                Q.push (i); }            }        }    }    returndist[2];}voidInit () { for(intI=1; i<=n; i++) {Dist[i]=INF; Vis[i]=false;  for(intj=1; j<=n; J + +) G[i][j]=INF; } dist[1] =0;}intMain () {point P[MAXN]; intCAS =1;  while(SCANF ("%d", &N), N) {Init ();  for(intI=1; i<=n; i++) {scanf ("%LF%LF",&p[i].x,&p[i].y); }         for(intI=1; i<=n; i++)        {             for(intj=1; j<=i; J + +) {G[i][j]=Len (P[i],p[j]); G[j][i]=G[i][j]; }        }        DoubleAns =SPFA (); printf ("Scenario #%d\n", CAS + +); printf ("Frog Distance =%.3lf\n\n", ans); }    return 0;}

POJ 2253 Frogger

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.