1623: [Usaco2008 Open]Cow Cars 奶牛飛車
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 565 Solved: 392
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
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
2OUTPUT DETAILS:
Two cows are possible, by putting either cow with speed 5 first and the cow
with speed 7 second.
題解:水題,沒得講,先排序,然後貪心。
代碼:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
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 v[50005];
int n,m,d,l,ans,k;
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++)
{
k=ans/m;
if(v[i]-k*d>=l)ans++;
}
printf("%d",ans);
return 0;
}