Frogger POJ 2253

Source: Internet
Author: User

http://poj.org/problem?id=2253

Test instructions: A frog a wants to jump to the other Frog B, because frog A's jumping range is not so big, so it needs to use some of its surrounding stones to reach the Frog B. Ask you the maximum number of hops in a road that is smaller than the maximum value in other roads. (that is, to ask for at least how much to jump)

#include <stdio.h>#include<string.h>#include<math.h>#include<algorithm>#include<queue>using namespaceStd;typedefLong LongLL;#defineOO 0x3f3f3f3f#defineMAXN 500DoubleMAPS[MAXN][MAXN], DIST[MAXN];intV[MAXN];intN;structnode{intx, y;} A[MAXN];DoubleFintIintj) {    return(Pow (sqrt (Double) a[i].x-a[j].x,2) +pow (Double) A[i].y-a[j].y,2)));}DoubleDij () {memset (V,0,sizeof(v));  for(intI=1; i<=n; i++) Dist[i]= maps[1][i]; dist[1] =0; v[1] =1;  for(intI=1; i<n; i++)    {        intindex; Doublemins =10000000;  for(intj=1; j<=n; J + +)        {            if(!v[j] && Dist[j] <mins) {Index=J; Mins=Dist[j]; }} V[index]=1;  for(intj=1; j<=n; J + +)        {            if(!V[j]) {                DoubleMaxs =max (mins, maps[index][j]); if(DIST[J]&GT;MAXS) Dist[j] =Maxs; }        }    }    returndist[2];}intMain () {intCNT =1;  while(SCANF ("%d", &N), N) { for(intI=1; i<=n; i++) scanf ("%d%d", &a[i].x, &a[i].y);  for(intI=1; i<=n; i++)        {             for(intj=1; j<i; J + +) {Maps[i][j]= Maps[j][i] =F (i, j); } Maps[i][i]=0; }       DoubleAns =Dij (); printf ("Scenario #%d\n", cnt++); printf ("Frog Distance =%.3f\n\n", ans); }    return 0;}
View Code

#include <algorithm>#include<queue>#include<stdio.h>#include<string.h>#include<vector>#include<math.h>using namespacestd;Const intMAXN =205;Const intOO =0xFFFFFFF;structpoint{Doublex, y;} P[MAXN];structnode{inty; DoubleLen; Node (intYDoublelen): Y (y), Len (len) {}};vector<node>G[MAXN];DoubleV[MAXN];//find the distance between two pointsDoubleLen (Point A, point B) {returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y));}voidSPFA () {Queue<int>Q; Q.push (1);  while(Q.size ()) {ints =Q.front ();        Q.pop (); intLen =g[s].size ();  for(intI=0; i<len; i++) {node Q=G[s][i]; if(V[s] < V[Q.Y] && Q.len <V[q.y]) {V[Q.Y]= Max (V[s], q.len);//to pick the biggest side of a roadQ.push (Q.Y); }        }    }}intMain () {intN, t=1;  while(SCANF ("%d", &N), N) {intI, J;  for(i=1; i<=n; i++) scanf ("%LF%LF", &p[i].x, &p[i].y);  for(i=1; i<=n; i++)             for(j=1; j<=n; J + +)            {                if(i = =j)Continue; DoubleLen =Len (P[i], p[j]);            G[i].push_back (Node (j, Len)); }         for(i=1; i<=n; i++) V[i]=Oo; v[1] =0;        SPFA (); if(t! =1) printf ("\ n"); printf ("Scenario #%d\n", t++); printf ("Frog Distance =%.3f\n", v[2]);  for(i=1; i<=n; i++) g[i].clear (); }    return 0;
View Code

Frogger POJ 2253

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.