洛谷 P2909 [USACO08OPEN]牛的车Cow Cars

传送门

题目大意:

m个车道。

如果第i头牛前面有k头牛,那么这头牛的最大速度会

变为原本的速度-k*D,如果速度小于l这头牛就不能行驶。

题解:贪心

让初始速度小的牛在前面

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 50009
using namespace std;

int n,m,d,l,k,ans;

int a[N],cnt[N];

int main(){
    scanf("%d%d%d%d",&n,&m,&d,&l);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int tmp=a[i]-d*cnt[j];
            if(tmp>=l){
                ans++;
                cnt[j]++;
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/zzyh/p/7792386.html