1623: [Usaco2008 open]cow Cars Cow rook Time limit:5 Sec Memory limit:64 MB
submit:325 solved:223
[Submit] [Status] [Discuss] DescriptionN cows numbered 1 to n are driving their cars to fly on the Nuedebia motorway. 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? Inputline 1th enters n,m,d,l four integers, followed by an integer of n lines for each line of SI. n<=50000Output output up to 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
[Submit] [Status] [Discuss]
A typical greedy, online someone to do with a heap, feel trouble.
First of all to order by speed, this should be the first feeling it ... Then, obviously, the back of the cow is superior to the ox before the test .... We think of each road as a collection, except that the elements in the collection are cows and these cows can be used as a speed-free cow, because the effect they have on the cows to be added in the back is only related to quantity. So obviously, we enumerate every cow, to make this cow to contribute to the answer, let it find the least of the cattle set (because the back of the cow is better, so there is no sub-set left behind the case of cattle), so the form of joining the cow is:
Suppose three roads, H stands for cattle:
①h②h h③h H H
④h h h⑤h H h ..... This time by "layer" full, understand the following ans/m just fine
H H H
1#include <bits/stdc++.h>2 using namespacestd;3 intn,m,d,l;4 ints[100000];5 intANS;6 intMain () {7Cin>>n>>m>>d>>L;8 for(intI=1; i<=n;i++){9scanf"%d",&s[i]);Ten } OneSort (s+1, s+n+1); A for(intI=1; i<=n;i++){ - intceng=ans/M; - if(s[i]-ceng*d>=m) { theans++; - } - } -cout<<ANS; + return 0; -}
Bzoj 1623: [Usaco2008 open]cow Cars Cow Rook