Time Limit:10 Sec Memory limit:128 MB
submit:302 solved:157 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
First in the initial order to the cow number, and then let the cow run T minute, according to the new position from small to large (the same position, the number of large in front).
Then sweep it from the back, and if the numbered cows run farther than the numbered cows, they are actually merged.
Record numbers starting with 1 monocytogenes sequence length is the answer.
From other blogs (a stream of mountains and rivers) saw a shorter writing: from the back to sweep again, to see which cows were killed
1 /*by Silvern*/2#include <algorithm>3#include <iostream>4#include <cstring>5#include <cstdio>6#include <cmath>7 #defineLL Long Long8 using namespacestd;9 Const intmxn=100010;Ten LL Read () { OneLL x=0, f=1;CharCh=GetChar (); A while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} - returnx*F; the } - LL V[MXN],P[MXN]; - LL ID[MXN]; - intN; LL T; + intcmpintAintb) { - if(P[a]==p[b])returnA>b; + returnp[a]<P[b]; A } at intMain () { -n=(LL) read (); -t=read (); - inti,j; - for(i=1; i<=n;i++){ -P[i]=read (); v[i]=read (); inp[i]+=v[i]*T; - } to for(i=1; i<=n;i++) id[i]=i; +Sort (id+1, id+n+1, CMP); - intlast=0, ans=0; the for(i=1; i<=n;i++){ * if(Id[i]>last) {ans++;last=id[i];} $ }Panax Notoginsengprintf"%d\n", ans); - return 0; the}
Bzoj3893 [Usaco2014 Dec]cow Jog