Frogger-poj 2253 (Dijkstra)

Source: Internet
Author: User

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 28802 Accepted: 9353

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
This problem can be used Dijkstra, the relaxation conditions can be changed, and changed to
          if (Dis[j]>max (Dis[stone],map[stone][j]) && (vis[j]==0)) {              dis[j]=max (Dis[stone],map[stone] [j]);           }
The result is a minimum value for the longest side of the path that can reach this point, and the output should be aware of the format
1#include <iostream>2#include <math.h>3#include <limits.h>4#include <algorithm>5#include <iomanip>6 using namespacestd;7 intnum;8 intvis[ $],stone[ $][2];9 intmap[ $][ $],dis[ $];Ten intDijkstra () { One      for(intI=0; i<num;i++){ Adis[i]=Int_max; -vis[i]=0; -     } thedis[0]=0; -      for(intI=0; i<num;i++){ -         intmin=Int_max; -         intStone; +          for(intj=0; j<num;j++){ -             if((vis[j]==0) &&min>Dis[j]) { +Stone=J; Amin=Dis[j]; at             } -         } -vis[stone]=1; -         if(min==Int_max) -              Break; -          for(intj=0; j<num;j++){ in             if(Dis[j]>max (Dis[stone],map[stone][j]) && (vis[j]==0)){ -dis[j]=Max (dis[stone],map[stone][j]); to             } +         } -     } the     returndis[1]; * } $ Panax Notoginseng intMain () { -  theCin>>num; +     intCount=1; A      while(num) { the          for(intI=0; i<num;i++){ +cin>>stone[i][0]>>stone[i][1]; -         } $          for(intI=0; i<num;i++){ $              for(intj=0; j<num;j++){ -Map[i][j]=pow ((stone[i][0]-stone[j][0]),2) +pow ((stone[i][1]-stone[j][1]),2); -             } the         } -         floatfdis=sqrt (Dijkstra ());Wuyicout<<fixed; thecout<<"Scenario #"<<count<<endl<<"Frog Distance ="<<setprecision (3) <<fdis<<endl<<Endl; -  Wucount++; -Cin>>num; About     } $  -     return 0; -}

Frogger-poj 2253 (Dijkstra)

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.