POJ-2253 Frogger Dijsktra Find the path with the smallest interval

Source: Internet
Author: User

Title Link: https://cn.vjudge.net/problem/POJ-2253

Test instructions

A forg needs to go from node 1 to node n
Now we're going to find a path with the smallest intervals.
What is the minimum interval of the question?

Ideas

Just use Dijsktra.
Find the path with the smallest interval

    1. Notice the comparison of floating-point numbers
Code
#include <cstdio>#include <vector>#include <queue>#include <cmath>using namespaceStdConst intmaxn= $, inf=0x3f3f3f3f;Const Doubleeps=1e-6;typedefpair<Double,int> Pair;structnode{intx, y; Node (intx=0,inty=0): x (x), Y (y) {}}NODE[MAXN+5];structedge{intFrom, to; Edge (intFrom=0,intto=0): From, to {}};vector<edge> edges;vector<int> G[MAXN+5];DoubleDist[maxn+5];voidAddedge (intFromintTo) {Edges.push_back-Edge (from, to); G[from].push_back (Edges.size ()-1); G[to].push_back (Edges.size ()-1);}inline BOOLEqualConst Double&a,Const Double&AMP;B) {return(A-b<=eps && b-a<=eps);}inline DoubleDis (Const int&a,Const int&AMP;B) {returnsqrt ((node[a].x-node[b].x) * (node[a].x-node[b].x) + (NODE[A].Y-NODE[B].Y) * (NODE[A].Y-NODE[B].Y));DoubleDij (void){ for(intI=0; i<=maxn;    i++) Dist[i]=inf;    Priority_queue<pair, Vector<pair&gt, greater<pair> > que; Que.push (Pair (0,1)); dist[1]=0; while(Que.size ()) {Pair x=que.top (); Que.pop ();if(!equal (X.first, Dist[x.second]))Continue;intFrom=x.second; for(intI=0; I<g[from].size (); i++) {Edge &e=edges[G[from][i]];intTo= (E.to==from) e.from:e.to;DoubleDis=dis (to, from), Mdis=max (Dist[from], Dis);if(Dist[to]<mdis | | equal (DIST[TO], MDIs))Continue;            Dist[to]=mdis;        Que.push (Pair (Dist[to], to)); }    }returndist[2];}intMainvoid){intN, cnt=1, X, y; while(SCANF ("%d", &n) = =1&& N) { for(intI=1; i<=n; i++) {scanf ("%d%d", &x, &y); Node[i]=node (x, y); for(intj=1; j<i;        J + +) Addedge (i, j); } printf ("Scenario #%d\nFrog Distance =%.3f\n\n", cnt++, Dij ()); }return 0;}
Time
Memory Length Lang submitted
16ms 1476kB 1878 g++ 2018-05-23 15:31:25

POJ-2253 Frogger Dijsktra Find the path with the smallest interval

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.