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

Description

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

Input

第1行输入N,M,D,L四个整数,之后N行每行一个整数输入Si.
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
 
数学题。。。(vi-l)/d就是第i头牛前面能有几头牛。。。
注意对vi-l<0的判断。。。。
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<queue>
 7 #include<map>
 8 #define maxn 50010
 9 #define maxm 1000010
10 #define inf 10000000000
11 using namespace std;
12 int cow[maxn],f[maxn];
13 int main(){
14     //freopen("output.txt","w",stdout);
15     int n,m,d,l;
16     //n=rand()%50000;m=rand()%50000;d=rand()%5000;l=rand()%1000000;
17     scanf("%d%d%d%d",&n,&m,&d,&l);
18     //printf("%d %d %d %d\n",n,m,d,l);
19     for(int i=1;i<=n;i++){
20         scanf("%d",&cow[i]);
21         //cow[i]=rand()%1000000;
22         if(cow[i]-l<0)cow[i]=-1;
23         else    cow[i]=(cow[i]-l)/d;
24     }
25     int ma=0,tmp=0,ans=0;
26     for(int i=1;i<=n;i++)if(cow[i]>=0){f[cow[i]]++;ma=max(ma,cow[i]);}
27     for(int i=ma+1;i>=0;i--){
28         if(f[i]>=m){tmp+=f[i]-m;ans+=m;}
29         if(f[i]<m){
30             if(tmp-m+f[i]>=0){
31                 tmp-=(m-f[i]);
32                 ans+=m;
33             }
34             else{
35                 ans+=(f[i]+tmp);
36                 tmp=0;
37             }
38         }
39     }
40     printf("%d",ans);
41     return 0;
42 }
View Code

 

posted @ 2015-10-13 12:02  HTWX  阅读(148)  评论(0编辑  收藏  举报