3314: [Usaco2013 nov]crowded cows

Source: Internet
Author: User

3314: [Usaco2013 nov]crowded cows time limit:1 Sec Memory limit:128 MB
submit:111 solved:79
[Submit] [Status] [Discuss] Description

Farmer John ' s n cows (1 <= n <= 50,000) is grazing along a one-dimensional fence. Cow i is standing at location X (i) and have height H (i) (1 <= x (i), H (i) <= 1,000,000,000). A cow feels "crowded" if there is another cow at least twice she height within distance D on she left, and also another co W at least twice she height within distance D on she right (1 <= D <= 1,000,000,000). Since crowded cows produce less milk, Farmer John would like to count the number of such cows. Please help him.

n Cattle on an axis, each cow has a height. A distance value of D is now given.

If a cow is on its left, within the range of D, if a cow is found to be at least twice times the height of the ox, it can be found on the right. The cow will feel uncomfortable.

Ask how many heads will feel uncomfortable.

Input

* Line 1:two integers, N and D.

* Lines 2..1+n:line i+1 contains the integers x (i) and H (i). The locations of all N cows is distinct.

Output

* Line 1:the number of crowded cows.

Sample Input6 4
10 3
6 2
5 3
9 7
3 6
11 2

INPUT Details:there is 6 cows, with a distance threshold of 4 for feeling crowded. Cow #1 lives at position x=10 and have height h=3, and so on.Sample Output2
OUTPUT Details:the cows at positions x=5 and x=6 is both crowded. HINT Source

Silver



Problem: A Meng Meng rmq question (hansbug: Spit Trough Translation-the input inside clearly said the location is distinct, that is, each cow coordinates only, this appearance although no substantive changes, but simplifies a lot of problems, after all, the title is left and right of the cow, Do not say this position = =), the coordinates sorted, and then the interval query maximum, and then no

1/**************************************************************2Problem:33143 User:hansbug4 language:pascal5 result:accepted6Time:608Ms7Memory:6008KB8****************************************************************/9  Ten var One I,j,k,l,m,n:longint; AB:Array[0..100000,1..2] ofLongint; -C:Array[0.. -,0..60000] ofLongint; - functionMax (x,y:longint): Longint; the          begin -               ifX>y ThenMax:=xElsemax:=y; -          End; - procedureSwapvarx,y:longint); +           varZ:longint; -           begin +z:=x;x:=y;y:=Z; A           End; at proceduresort (l,r:longint); -           varI,j,x:longint; -           begin -i:=l;j:=r;x:=a[(L+r)Div 2,1]; -                Repeat -                       whileA[i,1]<x DoInc (i); in                       whileA[j,1]>x DoDec (j); -                      ifI<=j Then to                         begin +Swap (A[i,1],a[j,1]); -Swap (A[i,2],a[j,2]); the Inc (I);d EC (j); *                         End; $                untilI>J;Panax Notoginseng                ifI<r Thensort (i,r); -                ifL<j Thensort (l,j); the           End; + functionGetmax (x,y:longint): Longint; A          varI:longint; the          begin +               ifY<x ThenExit (-1); -I:=trunc (LN (y-x+1)/LN (2)); $Exit (Max (C[I,X],C[I,Y-TRUNC (exp (LN) (2) (*i)) +1])); $          End; - begin - readln (n,m); the       fori:=1  toN DoREADLN (A[i,1],a[i,2]); -Sort1, n);Wuyi       fori:=1  toN Doc[0, I]:=a[i,2]; the       fori:=1  toTrunc (ln (n)/ln (2)+1) Do -           forj:=1  toN-TRUNC (exp (LN (2) (*i)) +1  Do WuC[i,j]:=max (c[i-1, j],c[i-1, J+trunc (exp (LN (2) * (I-1)))]); -k:=1; Fillchar (b[1],sizeof (b[1]),0); About       fori:=2  toN Do $          begin -                while(A[k,1]+M) <a[i,1] DoInc (k); -               ifGetmax (k,i-1) >= (A[i,2]*2) ThenB[i,1]:=1; -          End; AK:=n;fillchar (b[1],sizeof (b[1]),0); +       fori:=n-1 Downto 1  Do the          begin -                while(A[k,1]-M) >a[i,1] DoDec (k); $               ifGetmax (i+1, k) >= (A[i,2]*2) ThenB[i,2]:=1; the          End; thel:=0; fori:=1  toN DoInc (L, (B[i,1]+b[i,2])Div 2); the Writeln (l); the Readln; -   in End.

3314: [Usaco2013 nov]crowded cows

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.