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 |
哪位大哥帮我看看为什么WA啊?#include<iostream> using namespace std; int cmp(const void *a, const void *b) { return *(const __int64 *)a-*(const __int64 *)b; } int main() { int N=0,pos=0; __int64 lens[20001],sum=0,ans=0; scanf("%d",&N); for(int i=0;i<N;i++) { scanf("%I64d",&lens[i]); } qsort(lens,N,sizeof(__int64),cmp); while(N>1) { sum=lens[0]+lens[1]; ans+=sum; pos=2; while(sum>lens[pos++] && pos<N); memcpy(lens,lens+2,(pos-2)*sizeof(__int64)); lens[pos-1]=sum; memcpy(lens+(pos-2),lens+pos-1,(N-pos+1)*sizeof(__int64)); N--; } printf("%I64d",ans); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator