CodeForces - 660D Number of Parallelograms (数学几何)给出n个点问能组成的平行四边形个数

CodeForces - 660D
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

//题意:
给你n个点的坐标,问这n个点能形成多少个不相同的平行四边形?
//思路:
根据平行四边形的性质,两条对角线相交于一点,所以可以将这n个点两两连接并找出它们的中点并记录下来。
然后根据这些中点来判断有多少个平行四边形,因为只要有两个中点重合,那么它们两条线就可以组成一个平行四边形。
所以先找出重合中点的个数cnt,那么它们可以组成的平行四边形个数为C(cnt,2)。
将它们求和即为所求。
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define IN __int64
#define N 2010
#define M 1000000007
using namespace std;
ll C(int n,int k)
{
	ll ans=1;
	int i,j;
	for(i=n,j=1;i>n-k;i--,j++)
		ans*=i,ans/=j;
	return ans;
}
struct zz
{
	double x;
	double y;
}p[N];
bool cmp(zz a,zz b)
{
	if(a.x==b.x)
		return a.y<b.y;
	return a.x<b.x;
}
struct ss
{
	double x;
	double y;
}pp[N*N];
bool cmp1(ss a,ss b)
{
	if(a.x==b.x)
		return a.y<b.y;
	return a.x<b.x;
}
int main()
{
	int n,i,j,k;
	while(scanf("%d",&n)!=EOF)
	{
		for(i=0;i<n;i++)
			scanf("%lf%lf",&p[i].x,&p[i].y);
		sort(p,p+n,cmp);
		k=0;
		for(i=0;i<n-1;i++)
		{
			for(j=i+1;j<n;j++)
			{
				pp[k].x=(p[i].x+p[j].x)/2;
				pp[k++].y=(p[i].y+p[j].y)/2;
			}
		}
		int cnt=1;
		ll sum=0;
		sort(pp,pp+k,cmp1);	
		for(i=0;i<k;i++)
		{
			if(pp[i].x==pp[i+1].x&&pp[i].y==pp[i+1].y)
				cnt++;
			else
			{
				sum+=C(cnt,2);
				cnt=1;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值