1623: [Usaco2008 open]cow Cars Cow speed time limit:5 Sec Memory limit:64 MB
submit:291 solved:201
[Submit] [Status] [Discuss] n cows with a Description number of 1 to n are driving their cars to fly on the Nuedebia highway. The motorway has M (1≤m≤n) lanes. Cow I has an own speed limit of Si (l≤si≤1,000,000). After a bad driving accident, the cows become very careful to avoid collisions. In each lane, if a cow I in front of a K cow drive, the cow I speed limit will drop k*d units, that is, her speed will not exceed SI-KD (o≤d≤5000), of course, if the number is negative, then her speed will be 0. Nuedebia's high-speed road law stipulates that vehicles travelling on highways must not be less than/(1≤l≤1,000,000). So, do you calculate how many cows can travel on the freeway? Input line 1th enters n,m,d,l four integers, followed by an integer of n lines for each line of SI. N<=50000output output How many cows can travel on the freeway. Sample Input3 1 1 5//Three the cow drove past a passage. When a cow enters the channel, its speed V becomes v-d*x (X represents how many cows are in front of it), and it slows down, and the speed cannot be less than L
5
7
5
INPUT DETAILS:
There is three cows with one lane-drive in, a speed decrease
of 1, and a minimum speed limit of 5.
Sample Output2
OUTPUT DETAILS:
Cows is possible, by putting either cow with speed 5 first and the cow
With Speed 7 second.
HINT Source
Silver
The puzzle: Good greedy!!! I really don't understand why so many people still get a bunch of ...
1 var2 I,j,k,l,m,n,ans:longint;3A:Array[0..100000] ofLongint;4 procedureSwapvarx,y:longint); inline;5 varZ:longint;6 begin7z:=x;x:=y;y:=Z;8 End;9 proceduresort (l,r:longint); inline;Ten varI,j,x,y:longint; One begin Ai:=l;j:=r;x:=a[(L+r)Div 2]; - Repeat - whileA[i]<x DoInc (i); the whileA[j]>x DoDec (j); - ifI<=j Then - begin - swap (a[i],a[j]); + Inc (I);d EC (j); - End; + untilI>J; A ifI<r Thensort (i,r); at ifL<j Thensort (l,j); - End; - begin - readln (n,m,k,l); - fori:=1 toN Doreadln (A[i]); -Sort1, n); in fori:=1 toN Do if(A[i]-(ansDivm) *k) >=l ThenInc (ANS); - writeln (ans); to Readln; + End.
1623: [Usaco2008 open]cow Cars Cow Rook