POJ 1122 FDNY to the rescue! Floyd Print the path.

Source: Internet
Author: User

Main topic:

The speed of support for the New York Fire Department is one thing that is worth the pride of New Yorkers. But they want the fastest support to help them speed up their support. They want to dispatch a fire station closest to the ignition point. They want you to write a program to maintain the glorious tradition of the New York fire Station. What the software needs is the ability to get the address of the ignition point and the location of the fire station, the street intersection, the time from one intersection to another intersection. He is going to calculate how long it will take to get to the ignition point from the fire station.

Give you a specific address of the ignition point, the software should find out all fire stations to reach the ignition point of the distance, and from small to large to sort. So that firemen can dispatch personnel to the fire station.

#include <iostream>#include<cstdlib>#include<cstdio>#include<algorithm>#include<vector>#include<queue>#include<cmath>#include<cstring>using namespacestd;#defineINF 0XFFFFFFF#defineMAXN 40structpoint{inte, W;} DIST[MAXN];BOOLCMP (Point a,point B) {returnA.W <B.W;}intPATH[MAXN][MAXN], G[MAXN][MAXN], N;voidFloyd () { for(intk=1; k<=n; k++)    {         for(intI=1; i<=n; i++)        {             for(intj=1; j<=n; J + +)            {                if(G[i][j] > G[i][k] +G[k][j]) {G[i][j]= G[i][k] +G[k][j]; PATH[I][J]=Path[i][k]; }            }        }    }}voidPutpath (intStar,intEnd) {     while(Star! =End) {printf ("\t%d", Star); Star=Path[star][end]; } printf ("\t%d\n", Star);}intMain () {intA; CIN>>N;  for(intI=1; i<=n; i++)    {         for(intj=1; j<=n; J + +) {Path[i][j]=J; CIN>>G[i][j]; if(G[i][j] = =-1) G[i][j]=INF; }    }    intEnd, k =0;    Floyd (); CIN>>End;  while(SCANF ("%d", &a)! =EOF) {DIST[K].W=G[a][end]; Dist[k++].E =A; } sort (dist, Dist+K, CMP); cout<<"Org\tdest\ttime\tpath"<<Endl;  for(intI=0; i<k; i++) {printf ("%d\t%d\t%d", DIST[I].E, End, G[dist[i].e][end]);    Putpath (DIST[I].E, End); }    return 0;}

POJ 1122 FDNY to the rescue! Floyd the print path is OK

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.