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

哪位大牛帮我优化下代码

Posted by 407811696 at 2010-06-20 13:28:46 on Problem 3253
#include<iostream>
#include<algorithm>
using namespace std;
__int64 a[20010];
__int64 sum;
void insertsort(int i1,int i2)
{
	__int64 temp=a[i1];
	int i;
	for(i=i1+1;i<i2;++i)
		if(temp>a[i])
			a[i-1]=a[i];
		else
			break;
	a[i-1]=temp;
}
int main()
{
//	freopen("1.txt","r",stdin);
	int i,i1,i3;
	scanf("%d",&i);
	{
		sum=0;
		for(i1=0;i1<i;++i1)
			scanf("%I64d",&a[i1]);
		sort(a,a+i);
		__int64 i2;
		for(i1=1;i1<i;++i1)
		{
			i2=a[i1-1]+a[i1];
			sum+=i2;
			a[i1]=i2;
			insertsort(i1,i);
		}
		printf("%I64d\n",sum);
	}
	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