Simple POJ 2253 Frogger,dijkstra.

Source: Internet
Author: User

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.

The problem is to ask for all the paths, the biggest edge of the least of the one ...

Application of Dijkstra ideas, a mark ...

The code is as follows:

#include <iostream>#include<cstring>#include<cmath>#defineMax (A, b) (A>b a:b)using namespacestd;Const intinf=10e8;intN;intx[ About],y[ About];Doubleans[ About];BOOLvis[ About];voidDijkstra () {intK; DoubleMinn,len;  for(intI=1; i<=n;++i) {vis[i]=0; Ans[i]=INF; } ans[1]=0;  for(intI=1; i<=n;++i) {k=-1; Minn=INF;  for(intj=1; j<=n;++j)if(!vis[j] && ans[j]<Minn) {Minn=Ans[j]; K=J; }        if(k==-1)             Break; VIS[K]=1;  for(intj=1; j<=n;++j) {Len=sqrt ((Double(X[k])-x[j]) * (X[k]-x[j]) + (Double(Y[k])-y[j]) * (y[k]-y[j])); if(!vis[j] && max (Len,ans[k]) <Ans[j]) ans[j]=Max (len,ans[k]); }    }}intMain () {Ios::sync_with_stdio (false); COUT.SETF (iOS::fixed); Cout.precision (3); intcas=1;  for(cin>>n; n;cin>>n,++CAs) {         for(intI=1; i<=n;++i) Cin>>X[i]>>Y[i];        Dijkstra (); cout<<"Scenario #"<<cas<<Endl; cout<<"Frog Distance ="<<ans[2]<<endl<<Endl; }    return 0;}
View Code

Simple POJ 2253 Frogger,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.