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

实在没有辙了,为什么总是time limit exceed!!!!!!!!!!!!!!!!!!

Posted by zhanghua at 2007-04-30 16:21:05 on Problem 2231
#include<stdio.h>
#include<math.h>
#define Max 10000
void sort(__int64 b[],int n)
{
	int i,j;
	__int64 sum=0,temp;
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(i==j)continue;
			else
			{
				if(b[i]-b[j]>0)
				{
					temp=b[i]-b[j];
				}
				else
				{
					temp=b[j]-b[i];
				}
				sum=sum+temp;
			}
		}
	}
	printf("%I64d\n",sum*2);
}
main()
{
	int total,i;
	__int64 a[Max];
	if(scanf("%d",&total)==1)
	{
                  if(total>0&&total<=10000)
                  {
		for(i=0;i<total;i++)
		{
			scanf("%I64d",&a[i]);
		}
		sort(a,total);
                  }
	}
}

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