Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 291 Solved: 201
编号为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).那么,请你计算有多少奶牛可以在高速公路上行驶呢?
第1行输入N,M,D,L四个整数,之后N行每行一个整数输入Si.
N<=50000
输出最多有多少奶牛可以在高速公路上行驶.
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.
2 OUTPUT DETAILS: Two cows are possible, by putting either cow with speed 5 first and the cow with speed 7 second.
题解:说好的贪心嘛!!!实在不明白为啥那么多人还弄个堆。。。
1 var
2 i,j,k,l,m,n,ans:longint;
3 a:array[0..100000] of longint;
4 procedure swap(var x,y:longint);inline;
5 var z:longint;
6 begin
7 z:=x;x:=y;y:=z;
8 end;
9 procedure sort(l,r:longint);inline;
10 var i,j,x,y:longint;
11 begin
12 i:=l;j:=r;x:=a[(l+r) div 2];
13 repeat
14 while a[i]<x do inc(i);
15 while a[j]>x do dec(j);
16 if i<=j then
17 begin
18 swap(a[i],a[j]);
19 inc(i);dec(j);
20 end;
21 until i>j;
22 if i<r then sort(i,r);
23 if l<j then sort(l,j);
24 end;
25 begin
26 readln(n,m,k,l);
27 for i:=1 to n do readln(a[i]);
28 sort(1,n);
29 for i:=1 to n do if (a[i]-(ans div m)*k)>=l then inc(ans);
30 writeln(ans);
31 readln;
32 end.