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 chencq at 2007-07-23 15:32:30 on Problem 2231
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	long N;
	if((cin>>N)&&(N>=1)&&(N<=10000))
	{
		long pos[10000],sum=0,i;
		for(i=0;(i<N)&&(cin>>pos[i])&&(pos[i]>=0)&&(pos[i]<=1000000000);i++)
			for(int j=0;j<i;j++)
				sum+=2*fabs(pos[i]-pos[j]);
		if(i==N)
			cout<<sum<<endl;
	}
	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