| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么会是MLE??type arr=array[0..50000,1..5] of longint;
var a:arr;
i,j,k,l,n,t,z,q:longint;
v,tv:real;
h:real;
pv,nv:real;
function getvv(h:real;x:integer):real;
var s:integer;
hh:real;
begin
s:=a[x,4]*a[x,3];
if h<a[x,1] then hh:=0
else
if h>a[x,5] then hh:=a[x,2]
else
hh:=h-a[x,1];
getvv:=s*hh;
end;
function getv(h:real):real;
var i:integer;
tv:real;
begin
tv:=0;
for i:=1 to n do
tv:=tv+getvv(h,i);
getv:=tv;
end;
function geth(x,y:real):real;
var i,j:longint;
th,ttv:real;
begin
th:=(x+y)/2;
ttv:=getv(th);
if abs(ttv-v)<=1e-8 then begin geth:=th;exit;end;
if ttv>v then geth:=geth(x,th)
else if ttv<v then geth:=geth(th,y);
end;
procedure qs(x,y:longint);
var i,j,t,tt:longint;
begin
i:=x;j:=y;
t:=a[i,5];
a[0]:=a[i];
while i<j do
begin
while (i<j) and (t<a[j,5]) do dec(j);
if i<j then
begin
a[i]:=a[j];
inc(i);
end;
while (i<j) and (a[i,5]<t) do inc(i);
if i<j then
begin
a[j]:=a[i];
dec(j);
end;
end;
a[i]:=a[0];
if i+1<y then qs(i+1,y);
if x<i-1 then qs(x,i-1);
end;
{main}
begin
readln(z);
for q:=1 to z do
begin
readln(n);
for i:=1 to n do
begin
readln(a[i,1],a[i,2],a[i,3],a[i,4]);
a[i,5]:=a[i,1]+a[i,2];
end;
qs(1,n);
readln(v);
tv:=getv(a[n,5]);
if tv<v then begin writeln('OVERFLOW');continue;end;
pv:=0;
for i:=1 to n-1 do
begin
nv:=getv(a[i,5]);
if abs(nv-v)<=1e-8 then begin h:=a[i,5];break;end;
if nv>v then begin h:=geth(a[i-1,5],a[i,5]);break;end;
end;
writeln(h:0:2);
end;
end.
多问一点:这题的最优(标准)方法谁能讲一下,谢谢!!
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator