bzoj3375[usaco2004 Mar]paranoid Cows mad cow
Test instructions
The time period of milk production of n cows is given in turn, and the maximum k makes it possible for the former K cows to be completely covered by another time period. n≤100000.
Exercises
Currently in the processing of the first cow, the former i-1 only cows are legal. Then if the first i-1 cows in the time period of the left endpoint is less than the first cow time period of the left end of the cow right end point is not legal, and if the first i-1 cows in the time period of the left endpoint is greater than the first cow time period of the left end of the cow is less than the right end of the dairy cows is not legal, This is a greedy process that can be maintained with Stlset. Note that set must first insert a +inf and a negative inf to prevent border bombing.
Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <Set>5 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 #defineINF 0X3FFFFFFF7 #defineSit set<nd>::iterator8 using namespacestd;9 TenInlineintRead () { One CharCh=getchar ();intf=1, x=0; A while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} - while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); - returnf*x; the } - structnd{intL,r;BOOL operator< (ConstNd&a)Const{returnl==a.l?r<a.r:l<a.l;}}; - Set<nd>s;intN; - intMain () { +N=read (); S.insert ((ND) {INF,0}); S.insert (nd) {-inf,0}); -Inc (I,1, N) { + intX=read (), y=read (); AS.insert (ND) {x, y}); Sit a=s.find (ND) {x, y}); atSit b=--a; a++; Sit c=++a; a--; - if(B->r>=y&&b->l!=-inf) {printf ("%d", I-1);return 0;} - if(C->r<=y&&c->l!=inf) {printf ("%d", I-1);return 0;} - } -printf"%d", n);return 0; -}
20160909
bzoj3375[usaco2004 mar]paranoid Cows mad cow *