|
|
вернуться в форумI got AC!!!(0.04 and 225K) var c:char; a:array[1..100000] of integer; cyc1,cyc2,n,k,m,s,sm,i:longint; begin readln(n,m); cyc1:=0; while (not eof(input))and(cyc1<=n) do begin while (not eoln(input))and(cyc1<=n) do begin read(c); inc(cyc1); if c='*' then a[cyc1]:=-1 else a[cyc1]:=ord(c)-ord('0'); end; readln; end; k:=0; s:=0; i:=0; sm:=100000; for cyc1:= 1 to n do begin if a[cyc1]=-1 then begin s:=0;k:=0; end else begin if k<m then begin inc(k); s:=s+a[cyc1]; if k=m then begin if sm>s then begin sm:=s; i:=cyc1-m+1;end; end; end else begin s:=s+a[cyc1]-a[cyc1-m]; if sm>s then begin sm:=s;i:=cyc1-m+1;end; end; end; end; writeln(i); end. Re: I got AC!!!(0.04 and 225K) Послано Dilyan 16 июн 2005 18:37 try using an array only for the last K elements Re: I got AC!!!(0.04 and 225K) Послано Lurker 31 июл 2006 19:21 0.031 242 KB Program Buffer_Manager; Var A:array[0..10000] of integer; bj:boolean; N,K,c,s,i,mi,t,b:Longint; min:longint; ch:char; Begin Readln(n,k); min:=1000000; while (b<n)and(not(eof(input))) do begin while (b<n)and (not(eoln(input))) do begin Read(ch);inc(b);inc(i); if i>k then i:=1; t:=a[i]; if ch='*' then A[i]:=-1 Else A[i]:=ord(ch)-48; if a[i]=-1 then begin c:=0;s:=0; End Else if c=k then begin S:=s-t+a[i]; if s<min then begin min:=s;mi:=b-k+1; End; End Else begin inc(c);s:=s+a[i]; if c=k then if s<min then begin min:=s;mi:=b-k+1;End; End; End; Readln; End; writeln(mi); End. Re: I got AC!!!(0.04 and 225K) Just one feeling, Always found that most guys are very smart, but the code they write/post are quite terrible(I mean hard to read). I would recommend writing readable code with clear structure and comments as that's the rule in real world( long code with clean structure and readability is much better than urgly code with small size). Re: I got AC!!!(0.04 and 225K) Edited by author 05.08.2008 13:41 Edited by author 05.08.2008 13:41 |
|
|