2263 the topic meaning is to seek the beginning city to the end city the way of the maximum load capacity, can use Dijkstra or Floyd to solve, I use the Floyd feel more intuitive because only need to change the recursive to W[i][j] = Max (w[i][j],Min(w[i][k],w[k][j])); can get the answer, and Floyd writing is relatively simple but the complexity of N 3 times, but the problem is still able to AC
Source Codeproblem:2263user:lyz963254memory:760k time:32mslanguage:g++result:accepted Source Code #include<iostream>#include<cstdio>#include<cstring>using namespacestd; intMax (intXinty) {returnX>y?x:y; } intMin (intXinty) {returnX<y?x:y; } Const intM = -; intKase =0; intN,r; intnum; intW[m][m]; Charcity[m][ *]; Charstart[ *],dest[ *]; intIndexChar*s) {inti; for(i=0; i<num;i++){ if(!STRCMP (City[i],s))returni; } strcpy (City[i],s); Num++; returni; } intRead () {intI,j,k,limit; scanf ("%d%d",&n,&R); if(n==0)return 0; for(i=0; i<n;i++){ for(j=0; j<n;j++) W[i][j]=0; W[i][i]=9999999; } num=0; for(k=0; k<r;k++) {scanf ("%s%s%d",start,dest,&limit); I=index (START); J=index (dest); W[I][J]= W[j][i] =limit; } scanf ("%s%s", start,dest); return 1; } voidsolve () {inti,j,k; for(k=0; k<n;k++){ for(i=0; i<n;i++){ for(j=0; j<n;j++) {W[i][j]=Max (W[i][j],min (w[i][k],w[k][j)); }}} I=index (START); J=index (dest); printf ("Scenario #%d\n%d tons\n\n",++Kase,w[i][j]); } intMain () { while(Read ()) {solve (); } return 0; }View Code
1556 almost built to build a drunk, the algorithm directly apply Bellman-ford but the process of building the map is too disgusting, you need to judge whether the wall is blocked a, a, a, a vertex, blocking is not connected edge or even edge ...
#include <cstdio>#include<iostream>#include<cstring>#include<cmath>using namespacestd;#defineINF 20000000000#defineM 150structpoint{Doublex; Doubley;} P[M];structedge{intu; intv;} e[10050];intN//the number of roomsintPSize;//Number of pointsDoublewx[ -];//The x-coordinate of the wallDoublepy[ -][4];//coordinates of yDoubleMAP[M][M];//adjacency MatrixintEsize;//the number of edgesinti,j;DoubleDis (Point A,point b) {returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y));}DoubleCross (DoubleX1,DoubleY1,DoubleX2,DoubleY2,DoubleX3,DoubleY3)//determine if the point is above or below the line{ return(x2-x1) * (y3-y1)-(x3-x1) * (y2-y1);}BOOLOk (Point A,point B)//determine if two points can be connected at the time of constructing the net.{ if(a.x>=b.x)return false; BOOLFlag =true; inti =0; while(wx[i]<=a.x&&i<N) {i++; } while(wx[i]<b.x&&i<N) { if(Cross (A.x,a.y,b.x,b.y,wx[i),0) *cross (a.x,a.y,b.x,b.y,wx[i],py[i][0]) <0||Cross (a.x,a.y,b.x,b.y,wx[i],py[i][1]) *cross (a.x,a.y,b.x,b.y,wx[i],py[i][2]) <0||Cross (a.x,a.y,b.x,b.y,wx[i],py[i][3]) *cross (A.x,a.y,b.x,b.y,wx[i],Ten) <0) {flag=false; Break; } I++; } returnFlag;}DoubleBellmanintBegintend) { DoubleDist[m]; inti,j; for(i=0; i<m;i++) {Dist[i]=inf; } Dist[beg]=0; BOOLex =true; for(i=0; i<psize&&ex;i++) {ex=false; for(j=0; j<esize;j++){ if(dist[e[j].u]<inf&& (Dist[e[j].v]> (dist[e[j].u]+MAP[E[J].U][E[J].V]))) {DIST[E[J].V]= dist[e[j].u]+MAP[E[J].U][E[J].V]; Ex=true; } } } returndist[end];}voidsolve () {p[0].x =0; p[0].Y =5; PSize=1; for(i=0; i<n;i++) {scanf ("%LF",&Wx[i]); for(j=0;j<4; j + +) {p[psize].x=Wx[i]; scanf ("%LF",&p[psize].y); PY[I][J]=p[psize].y; PSize++; }} p[psize].x=Ten; P[psize].y=5; PSize++; for(i=0; i<psize;i++){ for(j=0; j<psize;j++) {Map[i][j]=inf; }} esize=0; for(i=0; i<psize;i++){ for(j=i+1; j<psize;j++){ if(Ok (P[i],p[j])) {Map[i][j]=Dis (P[i],p[j]); E[ESIZE].U=i; E[ESIZE].V=J; Esize++; }}} printf ("%.2lf\n", Bellman (0, psize-1));}intMain () { while(SCANF ("%d", &n)! =EOF) { if(n==-1) Break; Solve (); } return 0;}View Code
POJ 2263 POJ 1556