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

TLE help;

Posted by hduOZ at 2007-07-09 12:55:33 on Problem 3244
#include<iostream>
#include<algorithm>
using namespace std;
int x[200000],y[200000],z[200000];
bool cmp(int &z1,int &z2)
{
	return z1>z2;
}
int main()
{
	int n,i,j,z1,z2,z3;
	__int64 sum;
	while(scanf("%d",&n)==1&&n!=0)
	{
		sum=0;
		for(i=0;i<n;i++)
		{
			scanf("%d %d %d",&z1,&z2,&z3);
			x[i]=z1-z2;y[i]=z2-z3;z[i]=z3-z1;
		}
		sort(x,x+n,cmp);
		sort(y,y+n,cmp);
		sort(z,z+n,cmp);
		for(i=0;i<n;i++)
		{
			for(j=i+1;j<n;j++)
			{
				sum=sum+((x[i]-x[j])+(y[i]-y[j])+(z[i]-z[j]))/2;
			}
		}
		printf("%I64d\n",sum);
	}
}

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