bzoj1623 [Usaco2008 Open]Cow Cars 奶牛飞车

来源:互联网 发布:vba 递归算法 编辑:程序博客网 时间:2024/04/29 12:15

Description

  编号为1到N的N只奶牛正各自驾着车打算在牛德比亚的高速公路上飞驰.高速公路有M(1≤M≤N)条车道.奶牛i有一个自己的车速上限Si(l≤Si≤1,000,000).
    在经历过糟糕的驾驶事故之后,奶牛们变得十分小心,避免碰撞的发生.每条车道上,如果某一只奶牛i的前面有南只奶牛驾车行驶,那奶牛i的速度上限就会下降kD个单位,也就是说,她的速度不会超过Si - kD(O≤D≤5000),当然如果这个数是负的,那她的速度将是0.牛德比亚的高速会路法规定,在高速公路上行驶的车辆时速不得低于/(1≤L≤1,000,000).那么,请你计算有多少奶牛可以在高速公路上行驶呢?

Input

    第1行输入N,M,D,L四个整数,之后N行每行一个整数输入Si.

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.

看到那么多大神都做了这题……我也去写

贪心……排序一下显然速度小的要先合并

自然而然的想到了平衡树……(不要D我)

但是黄巨大说直接每次需按人数最少的加进去就好了

当然我这sillycross想不到这么精妙的做法

#include<cstdio>#include<algorithm>using namespace std;int v[50010];int n,m,d,l,forward,ans;inline int read(){    int x=0,f=1;char ch=getchar();    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}    return x*f;}int main(){n=read();m=read();d=read();l=read();for (int i=1;i<=n;i++)  v[i]=read();sort(v+1,v+n+1);for (int i=1;i<=n;i++)  {  forward=ans/m;  if (v[i]-forward*d>=l)ans++;  }printf("%d",ans);}


0 0
原创粉丝点击