`

poj 2231

 
阅读更多

题意:这道题目意思是要求直线上N个点相互之间距离的总和。

代码如下:

#include <iostream>
using namespace std;

__int64  a[10001];

int main()
{
	int i,j,N;
	while (cin>>N)
	{
		for (i=0;i<N;i++)
			scanf("%I64d",&a[i]);
		__int64 sum=0;
		for (i=0;i<N;i++)
		{
			__int64 temp=0;
			for (j=i+1;j<N;j++)
				temp+=abs(a[j]-a[i]);
			sum+=2*temp;

		}
		printf("%I64d\n",sum);
	}
	return 0;
}



 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics