很简单的一个模拟题,快排然后从小到大找比r大的数再平分就可以了。
program rp;
const
maxn=10000;
var
n:longint;
r:real;
a:array [0..maxn] of longint;
procedure init;
var
i:longint;
begin
readln(n,r);
for i:=1 to n do readln(a[i]);
end;
procedure qsort(l,r:longint);
var
i,j,m,t:longint;
begin
i:=l;
j:=r;
m:=a[(l+r) shr 1];
repeat
while a[i]<m do inc(i);
while a[j]>m do dec(j);
if i<=j then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
inc(i);
dec(j);
end;
until i>j;
if i<r then qsort(i,r);
if l<j then qsort(l,j);
end;
procedure main;
var
i:longint;
begin
for i:=1 to n do
begin
if a[i]>r then
r:=(a[i]+r)/2;
end;
end;
begin
assign(input,'rp.in'); reset(input);
assign(output,'rp.out'); rewrite(output);
init;
qsort(1,n);
main;
writeln(r:0:2);
close(input); close(output);
end.
本文介绍了一个简单的模拟题目解决方案,通过快速排序算法对输入数组进行排序,之后找到大于特定值r的所有元素,并将这些元素与r进行平均分配,直至r达到最大可能值。

被折叠的 条评论
为什么被折叠?



