"POJ 2253" Frogger
The minimum value of the maximum weight of the road per day in the path to the beginning to the end
Shortest path guaranteed maximum power Unicom minimum value (minimum)
Floyd 524K 79MS 1170B
#includeusing namespace STD;typedef structpoint{intx, y;} Point; Point p[233];Doubledis[233][233];intNintDCMP (Doublex) {returnx <-ESP? -1: x > ESP;}DoubleDis (intAintb) {return sqrt((p[a].x-p[b].x) * (p[a].x-p[b].x) *1.0+ (P[A].Y-P[B].Y) * (P[A].Y-P[B].Y) *1.0);}voidFloyd () {intI,j,k; for(k =0; K < n; ++K) { for(i =0; I < n; ++i) { for(j =0; J < I; ++J) {if(DCMP (Dis[i][j]-dis[i][k]) >0&& dcmp (Dis[i][j]-dis[k][j]) >0) {Dis[i][j] = dis[j][i] = max (dis[i][k],dis[k][j]); } } } }}intMain () {intI,j,z =0; while(~scanf("%d", &n) && N) { for(i =0; I < n; ++i) {scanf("%d%d", &P[I].X,&P[I].Y); for(j =0; J <= I; ++J) {Dis[j][i] = dis[i][j] = dis (j,i); }} Floyd ();printf("Scenario #%d\nfrog Distance =%.3lf\n\n", ++z,dis[0][1]); }return 0;}
Dijkstra 532K 0MS 1448B
#includeusing namespace STD;typedef structpoint{intx, y;} Point; Point p[233];Doubledis[233][233];Doubleds[233];BOOLvis[233];intNintDCMP (Doublex) {returnx <-ESP? -1: x > ESP;}DoubleDis (intAintb) {return sqrt((p[a].x-p[b].x) * (p[a].x-p[b].x) *1.0+ (P[A].Y-P[B].Y) * (P[A].Y-P[B].Y) *1.0);}DoubleDijkstra () {memset(Vis,0,sizeof(VIS));intI,p,j; for(i =1; I < n; ++i) Ds[i] =111111; ds[0] =0;DoubleM for(i =0; I < n; ++i) {m =111111; p =-1; for(j =0; J < N; ++J) {if(!vis[j] && m > ds[j]) {p = j; m = Ds[j]; } }if(p = =1)returnds[1]; VIS[P] =1; for(j =0; J < N; ++J) {if(!vis[j] && dcmp (Ds[j]-ds[p]) >0&& dcmp (Ds[j]-dis[p][j]) >0) {Ds[j] = max (ds[p],dis[p][j]); } } }}intMain () {intI,j,z =0; while(~scanf("%d", &n) && N) { for(i =0; I < n; ++i) {scanf("%d%d", &P[I].X,&P[I].Y); for(j =0; J <= I; ++J) {Dis[j][i] = dis[i][j] = dis (j,i); } }printf("Scenario #%d\nfrog Distance =%.3lf\n\n", ++z,dijkstra ()); }return 0;}
SPFA 536K 16MS 1409B
#includeusing namespace STD;typedef structpoint{intx, y;} Point; Point p[233];Doubledis[233][233];Doubleds[233];BOOLvis[233];intNintDCMP (Doublex) {returnx <-ESP? -1: x > ESP;}DoubleDis (intAintb) {return sqrt((p[a].x-p[b].x) * (p[a].x-p[b].x) *1.0+ (P[A].Y-P[B].Y) * (P[A].Y-P[B].Y) *1.0);}DoubleSPFA () {memset(Vis,0,sizeof(VIS));intU,i; for(i =1; I < n; ++i) Ds[i] =111111; ds[0] =0; Queue <int>Q Q.push (0); while(!q.empty ()) {u = Q.front (); Q.pop (); Vis[u] =0; for(i =0; I < n; ++i) {if(DCMP (Ds[i]-dis[u][i]) >0&& dcmp (Ds[i]-ds[u]) >0) {Ds[i] = max (Dis[u][i],ds[u]);if(!vis[i]) {Vis[i] =1; Q.push (i); } } } }returnds[1];}intMain () {intI,j,z =0; while(~scanf("%d", &n) && N) { for(i =0; I < n; ++i) {scanf("%d%d", &P[I].X,&P[I].Y); for(j =0; J <= I; ++J) {Dis[j][i] = dis[i][j] = dis (j,i); } }printf("Scenario #%d\nfrog Distance =%.3lf\n\n", ++Z,SPFA ()); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"POJ 2253" Frogger