随机RE机。。。

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

代码重发下。 ```c #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int k[10005]; int compare(int a,int b){ return a>b; } int main(){ int n,pos; long long sum=0; scanf("%d",&n); pos=n; for(int i=1;i<=n;++i) scanf("%d",&k[i]); sort(k+1,k+n+1,compare); for(int i=1;i<=n-1;++i){ k[pos-1]+=k[pos]; sum+=k[pos-1]; pos--; int temp=pos,ex; while(k[temp-1]<k[temp]){ ex=k[temp-1]; k[temp-1]=k[temp]; k[temp]=ex; temp--; if(temp==1) break; } } printf("%d",sum); return 0; } ```
by rts_GOD @ 2018-06-15 23:31:45


数组开小了
by nothingness @ 2018-06-16 07:14:20


@[rts_GOD](/space/show?uid=64767) while循环中需要加一句改成 ``` while(temp>1&&k[temp-1]<k[temp]) ``` 你当你不然temp可能会直接减到0,再-1就负数下标RE了。
by 一扶苏一 @ 2018-06-16 07:28:24


@[一扶苏一](/space/show?uid=65363) 谢大佬
by rts_GOD @ 2018-06-17 22:35:09


|