为什么只过了一个

P1090 [NOIP2004 提高组] 合并果子 / [USACO06NOV] Fence Repair G

不应该是堆吗???
by Acheing @ 2016-11-04 16:45:04


每一种题目都有多种多样的解法 比如这题我就是用合并排序(简单的 不优化的那种) 没用堆啊
by Red_w1nE @ 2016-11-04 17:11:37


```cpp const maxn=10001; type arr=array[1..maxn] of longint; var a,b:arr; i,n,ans,atop,btop,bbot:longint; procedure sort(var a:arr;l,r:longint); var tmp,x:longint; i,j:longint; begin i:=l;j:=r;x:=a[(l+r)div 2]; while i<=j do begin while (a[i]<x) do inc(i); while (a[j]>x) do dec(j); if (i<=j) then begin tmp:=a[i]; a[i]:=a[j]; a[j]:=tmp; inc(i); dec(j); end; end; if (i<r) then sort(a,i,r); if (l<j) then sort(a,l,j); end; begin // assign(input,'qsort.in'); // reset(input); read(n); for i:=1 to n+1 do begin a[i]:=maxlongint; b[i]:=maxlongint; end; for i:=1 to n do begin read(a[i]); end; atop:=1; btop:=1; bbot:=1; sort(a,1,n); for i:=1 to n-1 do begin if (atop+1<=n)and(a[atop+1]<=b[btop]) then begin b[bbot]:=a[atop]+a[atop+1]; atop:=atop+2; end else if ((btop+1<bbot)and(b[btop+1]<=a[atop]))or(atop>n) then begin b[bbot]:=b[btop]+b[btop+1]; btop:=btop+2; end else begin b[bbot]:=a[atop]+b[btop]; inc(atop); inc(btop); end; ans:=ans+b[bbot]; bbot:=bbot+1; end; writeln(ans); end. ```
by xxztztt @ 2016-11-12 21:05:49


不要再讨论群里发题解。
by taoxinyue2016 @ 2016-12-05 17:07:56


|