Codeforces--660D--Number of Parallelograms(几何性质)(组合数)

Time Limit: 4000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u

 Status

Description

You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points.

Input

The first line of the input contains integer n (1 ≤ n ≤ 2000) — the number of points.

Each of the next n lines contains two integers (xi, yi) (0 ≤ xi, yi ≤ 109) — the coordinates of the i-th point.

Output

Print the only integer c — the number of parallelograms with the vertices at the given points.

Sample Input

Input
4
0 1
1 0
1 1
2 0
Output
1

Source

Educational Codeforces Round 11

给出n个点的坐标,问你这些点可以组成多少个平行四边形,数据很大,判断平行边肯定是不可以的,会超时,平行四边形有一个性质,对角线互相平分,我们可以得到所有线段的中点,然后判断这些中点重合的有多少,一个中点代表两个给定点,所以每一对中点就可以表示一个平行四边形,判重的时候只需要一个for不会超时

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
struct node
{
	double x,y;
}p[2010],q[4000000+10];
int cmp(node s1,node s2)
{
	if(s1.x==s2.x)
	return s1.y<s2.y;
	return s1.x<s2.x;
}
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=0;i<n;i++)
		scanf("%lf%lf",&p[i].x,&p[i].y);
		sort(p,p+n,cmp);
		int cnt=0;
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				q[cnt].x=(p[i].x+p[j].x)/2;
				q[cnt++].y=(p[i].y+p[j].y)/2;
			}
		}
		sort(q,q+cnt,cmp);
		__int64 sum=0,cout=0;
		node s=q[0];
		for(int i=0;i<cnt;i++)
		{
			if(abs(s.x-q[i].x)<1e-6&&abs(s.y-q[i].y)<1e-6)
			cout++;
			else
			{
				if(cout>=1)
				sum+=cout*(cout-1)/2;
				cout=1;
				s=q[i];
			}
		}
		printf("%I64d\n",sum);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值