/*96655 ' s source code for mmemory:8604 KB time:63 mslanguage:g++ result:accepted*/#include<iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<cstring>#include<cstring>#include<vector>#include<queue>#include<stack>using namespacestd; Shortx[1006],y[1005],h[1005]; Shortxx[2005],hh[1005],xcnt,hcnt,d,ww,f;intdp[1003][2003];BOOLcmpintAintb) { returnA>b;}intMain () {intT; scanf ("%d",&T); while(t--) { intn,bb,cc,m; scanf ("%d%d%d%d",&n,&bb,&cc,&m); Xcnt=hcnt=0; for(intI=1; i<=n; ++i) {scanf ("%d%d%d",&x[i],&y[i],&H[i]); Xx[xcnt++]=X[i]; Xx[xcnt++]=Y[i]; Hh[hcnt++]=H[i]; } xx[xcnt++]=BB; Hh[hcnt++]=0; Sort (xx,xx+xcnt); Sort (hh,hh+hcnt,cmp); D=1; for(intI=1; i<xcnt; i++) if(xx[i]!=xx[i-1]) xx[d++]=Xx[i]; Xcnt=d,d=1; for(intI=1; i) if(hh[i]!=hh[i-1]) hh[d++]=Hh[i]; Hcnt=D; Vector<int>a[hcnt+1]; Memset (DP,-1,sizeof(DP)); intans=0x3f3f3f3f; for(intI=0; i<xcnt; i++) dp[hcnt-1][i]=ans; for(intI=1; i<=n; i++) { intID; for(intj=0; j) if(h[i]==Hh[j]) {ID=J; Break; } intS=lower_bound (Xx,xx+xcnt,x[i])-xx; intT=lower_bound (Xx,xx+xcnt,y[i])-xx; A[id].push_back (s); A[id].push_back (t); for(intJ=s; j<=t; ++j) Dp[id][j]=ans; } f=lower_bound (XX,XX+XCNT,BB)-xx; for(intI=0; i) { if(dp[i][f]!=-1) {Dp[i][f]=cc-Hh[i]; WW=i; Break; } } for(intI=WW; i1; ++i) { for(intj=0; j<xcnt; J + +) { if(dp[i][j]<ans&&dp[i][j]!=-1) { ints,t; for(intk=1; K<a[i].size (); k+=2) { if(a[i][k-1]<=j&&a[i][k]>=j) {s=a[i][k-1]; T=A[i][k]; Break; } } intl=xx[j]-xx[s],r=xx[t]-Xx[j]; Dp[i][s]=min (dp[i][s],dp[i][j]+l); Dp[i][t]=min (dp[i][t],dp[i][j]+R); } } for(intj=0; J<a[i].size (); ++j) {intp=A[i][j]; if(dp[i][p]!=-1&&dp[i][p]<ans) { for(intk=i+1; k) if(dp[k][p]!=-1) {Dp[k][p]=min (dp[k][p],dp[i][p]+hh[i]-Hh[k]); Break; } } } } for(intI=0; i<xcnt; i++) ans=min (ans,dp[hcnt-1][i]); printf ("%d\n", ans); } return 0;}
View Code
POJ 1661 Help Jimmy