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