bzoj3410[usaco2009 dec]selfish grazing The selfish grass eater
Test instructions
n intervals, the maximum number of interval sets is not covered by each other. n≤50000
Exercises
Seems to be the third occurrence of such a problem ~ But the range can reach 10^9, can not DP Qaq film a one-point finding as long as the right end of the interval sorting and then greedy to take.
Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineMAXN 501005 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 using namespacestd;7 8InlineintRead () {9 CharCh=getchar ();intf=1, x=0;Ten while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} One while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); A returnf*x; - } - structnd{intL,r;} NDS[MAXN]; theInlineBOOLcmpConstnd &a,Constnd &b) {returna.r<B.R;} - intN,r,ans; - intMain () { -N=read (); Inc (I,1, N) {intA=read (), B=read (); nds[i]=(ND) {a, b};} +Sort (nds+1, nds+1+n,cmp); -Inc (I,1, N) { + if(nds[i].l>=r) ans++,r=NDS[I].R; A } atprintf"%d", ans);return 0; -}
20160810
bzoj3410[usaco2009 dec]selfish grazing selfish grass eater *