bzoj3375[usaco2004 mar]paranoid Cows mad cow *

Source: Internet
Author: User

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 *

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.