3893: [Usaco2014 dec]cow Jog

Source: Internet
Author: User

3893: [Usaco2014 dec]cow Jog time limit:10 Sec Memory limit:128 MB
submit:174 solved:87
[Submit] [Status] [Discuss] Description

The cows is out exercising their hooves again! There is N cows jogging on a infinitely-long single-lane track (1 <= N <= 100,000). Each of the cow starts at a distinct position in the track, and some cows jog at different speeds. With only one lane on the track, cows cannot pass to each of the other. When a faster cow catches up to another cow, she had to slow down to avoid running into the other cow, becoming part of th E same running group. The cows would run for T minutes (1 <= T <= 1,000,000,000). Farmer John determine how many groups would be is left at the this time. Cows should is considered part of the same group if they is at the same position at the end of T minutes.
On an infinitely long runway there are n cows, each with its own initial position and speed of running. Cows cannot penetrate each other. When a cow catches up with another cow, it has to slow down and become a group. There are several groups after the T minute.

Inputthe first line of input contains the integers N and T. The following N lines each contain the initial position and speed of a single cow. Position is a nonnegative integer and speed is a positive integer; Both numbers is at the most 1 billion. All cows start at distinct positions, and these would be given in increasing order in the input.

Outputa single integer indicating how many groups remain after T minutes.

Sample Input5 3
0 1
1 2
2 3
3 2
6 1Sample Output3HINT Source

Silver

The puzzle: Obviously, the speed of a cow will not be affected by the back of the cow, so direct O (n) sweep again, like a daleitai can, this looks like the number of heaps will come out

1/**************************************************************2Problem:38933 User:hansbug4 language:pascal5 result:accepted6Time:1204Ms7Memory:1008KB8****************************************************************/9  Ten var One I,j,k,l,m,n,ans:longint; AB:Array[0..100100] ofLongint; - T:int64; - begin the readln (n,t); -       fori:=1  toN Doreadln (A[i],b[i]); -a[n+1]:=Maxlongint; -b[n+1]:=Maxlongint; +l:=n+1; -       forI:=nDownto 1  Do +          begin A               if(a[i]+ (B[i]*t)) < (a[l]+ (b[l]*t)) Then at                  begin - Inc (ANS); -l:=i; -                  End; -          End; - writeln (ans); in End.

3893: [Usaco2014 dec]cow Jog

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.