http://www.lydsy.com/JudgeOnline/problem.php?id=1623
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 624 Solved: 433
[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.
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.
OUTPUT DETAILS:
Two cows are possible, by putting either cow with speed 5 first and the cow
with speed 7 second.
HINT
Source
优先队列存储每条道路上的人数,每头牛判断能否在加在最少人数的道路上
1 #include <algorithm> 2 #include <cstdio> 3 #include <queue> 4 5 using namespace std; 6 7 inline void read(int &x) 8 { 9 x=0; register char ch=getchar(); 10 for(; ch>'9'||ch<'0'; ) ch=getchar(); 11 for(; ch>='0'&&ch<='9'; ch=getchar()) x=x*10+ch-'0'; 12 } 13 14 const int N(5e4+5); 15 16 int n,m,d,l,ans,s[N]; 17 18 priority_queue<int,vector<int>,greater<int> >que; 19 20 int Presist() 21 { 22 read(n),read(m), read(d),read(l); 23 for(int i=1; i<=n; ++i) read(s[i]); 24 sort(s+1,s+n+1); 25 for(int i=1; i<=m; ++i) que.push(0); 26 for(int u,i=1; i<=n; ++i) 27 { 28 u=que.top(); 29 if(s[i]-u*d>=l) 30 ans++,que.pop(), 31 que.push(++u); 32 } 33 printf("%d ",ans); 34 return 0; 35 } 36 37 int Aptal=Presist(); 38 int main(int argc,char**argv){;}