Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位大哥帮我看看为什么WA啊?

Posted by mlh at 2010-03-02 15:31:25 on Problem 3253
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator