Title Link: http://poj.org/problem?id=2528
Test instructions: There are n Zhang Hai newspaper to paste, each need to use the interval for L to R, the back can be affixed to the top before, that is, before the block, we can see a few posters at the end;
We can deal with it backwards, because we can see the last post, if the interval has been affixed to the result is not added, not posted on the +1 and marked;
Because the data range is too large, use the line segment tree
#include <stdio.h>#include<math.h>#include<string.h>#include<algorithm>using namespacestd;#defineN 10100#defineLson r<<1#defineRson r<<1|1structpost{intL,r;} P[n];structsegtree{intL, R, Iscover; intMid () {return(L+R)/2; }}a[n* -];inthash[4*N];voidUp (intR) { if(A[r]. l!=A[r]. R)if(a[lson].iscover==1&& a[rson].iscover==1)//update up, if the left and right subtrees are overwritten, then he will be overwrittenA[r].iscover =1;}voidBuildsegtree (intRintLintR) {A[r].iscover=0; A[R]. L= L; A[R]. R =R; if(L = =R)return ; Buildsegtree (Lson, L, A[r]. Mid ()); Buildsegtree (Rson, A[r]. Mid ()+1, R);}intJudgeintRintLintR) { if(a[r].iscover==1) return 0;//be overwritten return 0; if(A[r]. r = = R && a[r]. L = =L) {a[r].iscover=1; return 1; } intans; if(l>A[r]. Mid ()) ans=judge (Rson, L, R); Else if(r<=A[r]. Mid ()) ans=judge (Lson, L, R); Else { intANS1 =judge (Lson, L, A[r]. Mid ()); intAns2 = Judge (Rson, A[r]. Mid () +1, R); Ans= Ans1 | Ans2;//as long as there is a not covered on the description can be affixed;} up (R); returnans;}intMain () {intT, N, K; scanf ("%d", &T); while(t--) {scanf ("%d", &N); K=0; for(intI=1; i<=n; i++) {scanf ("%d%d", &p[i]. L, &P[i]. R); Hash[k++]=p[i]. L-1;//Prevents the number of nonadjacent neighbors from becoming adjacent after the discretization occurs .hash[k++]=P[i]. L Hash[k++]=p[i]. r+1; Hash[k++]=P[i]. R } sort (hash, hash+k); intLen = Unique (Hash, hash+k)-Hash; Buildsegtree (1,1, Len); intresult =0; for(intI=n; I>0; i--) { intL = Lower_bound (Hash, Hash+len, P[i]. L)-Hash; intR = Lower_bound (Hash, Hash+len, P[i]. R)-Hash; intAns=judge (1, L, R); if(ans = =1) Result++; } printf ("%d\n", result); } return 0;}
View Code
Mayor ' s Posters---poj2528 segment tree, discretization