bzoj3410[usaco2009 dec]selfish grazing selfish grass eater *

Source: Internet
Author: User

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 *

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.