BZOJ 1623: [Usaco2008 Open]Cow Cars 奶牛飞车 (贪心)
1623: [Usaco2008 Open]Cow Cars 奶牛飞车
Time Limit: 5 Sec Memory Limit: 64 MB Submit: 386 Solved: 266 [Submit][Status][Discuss]
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
OUTPUT DETAILS:
Two cows are possible, by putting either cow with speed 5 first and the cow with speed 7 second.
思路:贪心。尽可能让这些车均匀分布。 以及初始就干掉那些最大速度小于L的。然后按照s[i]从小到大排序,先放置速度小的。
1/* ***********************************************
2Author :111qqz
3Created Time :2016年04月04日 星期一 02时26分34秒
4File Name :code/bzoj/1623.cpp
5************************************************ */
6
7#include <cstdio>
8#include <cstring>
9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=5E4+7;
34int n,m;
35int s[N];
36int D,L;
37int num[N]; //num[i]表示第i个车道现在的有多少辆车
38int main()
39{
40 #ifndef ONLINE_JUDGE
41 freopen("code/in.txt","r",stdin);
42 #endif
43
44 ios::sync_with_stdio(false);
45 cin>>n>>m>>D>>L;
46 int cnt = 0 ;
47 int total = n ;
48 for ( int i = 0;i < n ; i++)
49 {
50 int x;
51 cin>>x;
52 if (x>=L)
53 {
54 s[cnt++] = x;
55 }
56 }
57 int sad = n-cnt;
58 n = cnt;
59 sort(s,s+n);
60 ms(num,0);
61 for ( int i = 0 ; i < n ; i++)
62 {
63 int sp;
64 sp = s[i]-num[i%m]*D;
65 if (sp>=L)
66 {
67 num[i%m]++;
68 }
69 else
70 sad++;
71 }
72 cout<<total-sad<<endl;
73
74 #ifndef ONLINE_JUDGE
75 fclose(stdin);
76 #endif
77 return 0;
78}