3410: [Usaco2009 dec]selfish grazing selfish grass-eater

Source: Internet
Author: User

3410: [Usaco2009 dec]selfish grazing selfish grass eater time limit:3 Sec Memory limit:128 MB
submit:71 solved:62
[Submit] [Status] [Discuss] Description John had N (1≤n≤50000) cows, and John's lawn could be considered a straight line. Each cow only likes to eat grass within a certain range.    The first cow likes to eat grass in the interval (Si,ei), 1≤si<ei≤1,000,000,00. Cows are selfish, they don't like to share their favorite fields with other cows, so John wants to make sure that no two cows share the field they like to eat grass. If cow I and cow J want to eat grass at the same time, then be satisfied: Si>=ej or EI≤SJ. John wants to know at the same time how many cows can eat grass at the same time?    Input line 1th: an integer n. 2nd to N+1: line i+l has two integer si,ei. Output an integer, up to how many cows can eat grass at the same time. Sample Input5
2 4
1 12
4 5
7 10
7 8Sample Output3HINT

1,3,4 A total of 3 cows can eat grass at the same time, 1,3,5 can also.

Source

Silver

Problem: A greedy water question = = ... Obviously for the same right boundary range, it is clear that the smallest selection is not wrong, so only keep the range of small, and then sort, greedy water over ...

1/**************************************************************2Problem:34103 User:hansbug4 language:pascal5 result:accepted6Time:212Ms7Memory:696KB8****************************************************************/9  Ten var One I,j,k,l,m,n,t:longint; AA:Array[0..60000,1..2] ofLongint; - procedureSwapvarx,y:longint); -           varZ:longint; the           begin -z:=x;x:=y;y:=Z; -           End; - proceduresort (l,r:longint); +           varI,j,x,y:longint; -           begin +i:=l;j:=r;x:=a[(L+r)Div 2,2];y:=a[(L+r)Div 2,1]; A                Repeat at                       while(A[i,2]&LT;X)or(A[i,2]=X) and(A[i,1]>y)) DoInc (i); -                       while(A[j,2]&GT;X)or(A[j,2]=X) and(A[j,1]<y)) DoDec (j); -                      ifI<=j Then -                         begin -Swap (A[i,1],a[j,1]); -Swap (A[i,2],a[j,2]); in Inc (I);d EC (j); -                         End; to                untilI>J; +                ifI<r Thensort (i,r); -                ifL<j Thensort (l,j); the           End; * begin $ READLN (n);Panax Notoginseng       fori:=1  toN DoREADLN (A[i,1],a[i,2]); -Sort1, n); thea[0,1]:=0; a[0,2]:=0; +t:=0; l:=0; A       fori:=1  toN Do the          ifA[i,2]<>a[i-1,2] Then +             ifA[i,1]>=t Then -                begin $T:=a[i,2]; $ Inc (L); -                End; - Writeln (l); the Readln; - End.

3410: [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.