# BZOJ 1623: [Usaco2008 Open]Cow Cars 奶牛飞车【二分+贪心】

## 1623: [Usaco2008 Open]Cow Cars 奶牛飞车

Time Limit: 5 Sec Memory Limit: 64 MB

Description

Input

N<=50000

Output

Sample Input

3 1 1 5//三头牛开车过一个通道.当一个牛进入通道时，它的速度V会变成V-D*X(X代表在它前面有多少牛),它减速后，速度不能小于L
5
7
5
INPUT DETAILS:
There are three cows with one lane to drive on, a speed decrease
of 1, and a minimum speed limit of 5.

Sample Output

2
OUTPUT DETAILS:
Two cows are possible, by putting either cow with speed 5 first and the cow
with speed 7 second.

#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,D,L,a[50005],Ans;
bool check(int i){
int Now=0,cnt=0;
for(;i<=n;i++)
if(a[i]-D*Now>=L){
cnt++;
if(cnt==m) cnt=0,Now++;
}else return 0;
return 1;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("prob.in","r",stdin);
freopen("prob.out","w",stdout);
#endif
scanf("%d%d%d%d",&n,&m,&D,&L);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
sort(a+1,a+1+n);
for(int L=0,R=n,mid=(R+L)>>1;L<=R;mid=(R+L)>>1)
if(check(mid)) Ans=mid,R=mid-1;else L=mid+1;
printf("%d\n",n-Ans+1);
return 0;
}
posted @ 2018-05-15 20:16  XSamsara  阅读(99)  评论(0编辑  收藏  举报