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 |
留ac代码帮助后人……丫的这题坑人地方数不胜数In Reply To:珍惜生命,远离此题 Posted by:xuhaoran510 at 2011-06-21 13:39:48 const eps=0; type pack=record sign:longint; data:extended; end; var f,sum:array[0..100010] of pack; bg,ed:array[0..100010] of longint; function sgn(const x:extended):longint; begin if abs(x)<=eps then exit(0); if x>eps then exit(1); exit(-1); end; function cmp(const x,y:pack):longint; begin if (x.sign=-1)and(y.sign=1) then exit(-1); if (x.sign=1)and(y.sign=-1) then exit(1); if x.sign=1 then begin if abs(x.data-y.data)<=eps then exit(0); if x.data>y.data then exit(1); exit(-1); end else begin if abs(x.data-y.data)<=eps then exit(0); if x.data>y.data then exit(-1); exit(1); end; end; function mult(const x,y:pack):pack; begin with mult do begin sign:=x.sign*y.sign; data:=x.data+y.data; end; end; function divd(const x,y:pack):pack; begin with divd do begin sign:=x.sign*y.sign; data:=x.data-y.data; end; end; function query(bg,ed:longint):pack; var ans,x,min,max:pack; i:longint; begin sum[bg]:=f[bg]; if sum[bg].sign=1 then begin with min do begin sign:=1; data:=0; end; if cmp(sum[bg],min)=-1 then min:=sum[bg]; with max do begin sign:=-1; data:=1e50; end; end else begin with min do begin sign:=1; data:=0; end; with max do begin sign:=-1; data:=1e50; end; if cmp(sum[bg],max)=1 then max:=sum[bg]; end; ans:=sum[bg]; for i:=bg+1 to ed do begin sum[i]:=mult(sum[i-1],f[i]); if sum[i].sign=1 then begin if abs(min.data-1e50)>eps then begin x:=divd(sum[i],min); if cmp(x,ans)=1 then ans:=x; end; if cmp(sum[i],min)=-1 then min:=sum[i]; end else begin if abs(max.data-1e50)>eps then begin x:=divd(sum[i],max); if cmp(x,ans)=1 then ans:=x; end; if cmp(sum[i],max)=1 then max:=sum[i]; end; if cmp(sum[i],ans)=1 then ans:=sum[i]; end; exit(ans); end; procedure print(ans:pack); var temp,final,w:extended; wc,tt:longint; begin temp:=exp(5000); if ans.sign=-1 then write('-'); w:=ans.data/ln(10); if (ln(0.9995)<=ans.data+1e-9)and(ans.data<ln(9.9995)) then begin writeln(exp(ans.data):0:3); exit; end; if w<0 then wc:=-trunc(abs(w)-1e-8)-1 else wc:=trunc(w+eps); wc:=0; if ans.data>0 then begin final:=1; while ans.data>5000 do begin final:=final*temp; while final>=9.9995 do begin final:=final/10; inc(wc); end; ans.data:=ans.data-5000; end; final:=final*exp(ans.data); while final>=9.9995 do begin final:=final/10; inc(wc); end; end else begin final:=1; ans.data:=abs(ans.data); while ans.data>5000 do begin final:=final/temp; while final<0.9995 do begin final:=final*10; dec(wc); end; ans.data:=ans.data-5000; end; final:=final/exp(ans.data); while final<0.9995 do begin final:=final*10; dec(wc); end; end; tt:=trunc(final*1000+0.5); if (tt<1000)or(tt>9999) then while true do ; writeln(final:0:3,'E',wc); end; procedure lemon(); var n,i,all,curt:longint; x:extended; zero:boolean; ans,xx:pack; begin readln(n); for i:=1 to n do begin read(x); with f[i] do begin sign:=sgn(x); if sign<>0 then data:=ln(abs(x)); end; end; all:=0; curt:=0; for i:=1 to n do if f[i].sign=0 then begin if curt+1<=i-1 then begin inc(all); bg[all]:=curt+1; ed[all]:=i-1; end; curt:=i; end; if curt<>n then begin inc(all); bg[all]:=curt+1; ed[all]:=n; end; zero:=false; for i:=1 to n do if f[i].sign=0 then zero:=true; with ans do begin sign:=-1; data:=1e50; end; for i:=1 to all do begin xx:=query(bg[i],ed[i]); if cmp(xx,ans)=1 then ans:=xx; end; for i:=1 to n do if (f[i].sign<>0)and(cmp(f[i],ans)=1) then ans:=f[i]; if zero then if ans.sign=-1 then begin writeln('0.000'); exit; end; print(ans); end; begin {$IFNDEF ONLINE_JUDGE} assign(input,'2830.in'); reset(input); assign(output,'2830.out'); rewrite(output); {$ENDIF} while not seekeof(input) do lemon(); end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator