POJ 2253 Frogger (Dijkstra algorithm + preprocessing)

Source: Internet
Author: User

Frogger
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 27020 Accepted: 8797

Description

Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who was sitting on another stone. He plans to visit she, but since the water was dirty and full of tourists ' sunscreen, he wants to avoid swimming and instea D reach her by jumping.
Unfortunately Fiona ' s stone is out of the his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach hers by a sequence of several small jumps.
To execute a given sequence of jumps, a frog's jump range obviously must is at least as long as the longest jump occuring In the sequence.
The frog distance (humans also call it minimax distance) between both stones therefore is defined as the minimum necessary Jump range possible paths between the stones.

You is 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 would contain one or more test cases. The first line of all test case would contain the number of stones N (2<=n<=200). The next n lines each contain the integers xi,yi (0 <= xi,yi <=) representing the coordinates of stone #i. ston E #1 is Freddy's stone, stone #2 is Fiona's Stone, the other n-2 stones was 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 was replaced by the TES The T Case number (they was numbered from 1) and Y was replaced by the appropriate real number, printed to three decimals. Put a blank line after all test case, even after the last one.

Sample Input

20 03 4317 419 418 50

Sample Output

Scenario #1Frog Distance = 5.000Scenario #2Frog Distance = 1.414

Source

ULM Local 1997



Test instructions: There is a river with Frog A and Frog B in the river. Frog a stays on stone 1, frog B stays on the stone 2, there are known to be a total of n stones in the river, numbered 1~n, all the coordinates of the stone are known. Now frog a wants to find frog B to play, the minimum jumping distance required for frog a.


Parsing: This test instructions is very simple, we need to preprocess the data first, built an Dijkstra algorithm, but note, here is the frog a stone to the Frog B is located on the path of the largest edge of the stone, so the relaxation operation to slightly change a shape.




AC Code:

#include <cstdio> #include <cstring> #include <algorithm> #include <cmath>using namespace std;#        Define MAXN 5 #define INF 123456789struct node{int x, y;};                           Vertex structural body int V;                 Vertex number node NODE[MAXN]; Double W[MAXN][MAXN], DIS[MAXN];                 W: adjacency matrix of the non-graph, dis: shortest path int VIS[MAXN]; Access the array double dist (Node A, Node B) {//a,b Two points from the distance between return sqrt ((double) ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.      (Y-B.Y)));         Note that the parameters of the sqrt () function must be strongly converted to a double type, otherwise it will ce}void Dijkstra () {memset (Vis, 0, sizeof (VIS)); preprocessing for (int i=1; i<=v; i++) dis[i] = (i==1)?    0:inf;        for (int i=1; i<=v; i++) {//dijkstra int x, m = INF;            for (int y=1; y<=v; y++) if (!vis[y] && dis[y] <= m) {x = y;        m = dis[x];        } Vis[x] = 1;         for (int y=1; y<=v; y++) dis[y] = min (Dis[y], Max (dis[x], w[x][y])); Relaxation operation after deformation}}int main () {    #ifdef sxk freopen ("In.txt", "R", stdin);    #endif//sxk int t = 0; while (scanf ("%d", &v)!=eof && V) {for (int i=1; i<=v; i++) scanf ("%d%d", &node[i].x, &node[i        ].Y);  for (int i=1; i<=v; i++)//processing data, built without map for (int j=i; j<=v; j + +) W[i][j] = W[j][i]              = Dist (Node[i], node[j]);          Dijkstra ();     Process if (t) printf ("\ n");        There is a blank line between each sample, but the last example does not follow!!!    printf ("Scenario #%d\nfrog Distance =%.3lf\n", ++t, dis[2]); } return 0;}


Small Package Benefits: If you want to know more about sqrt (), click: Compile Error sqrt () call ^_^



POJ 2253 Frogger (Dijkstra algorithm + preprocessing)

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.