首页 技术 正文
技术 2022年11月14日
0 收藏 698 点赞 3,286 浏览 1051 个字

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

4
0 1
1 0
1 1
2 0

Output

1

题意:

给你n个点的坐标,问这n个点能形成多少个不相同的平行四边形?

思路:

(1) 根据平行四边形的性质,两条对角线相交于一点,所以可以将这n个点两两连接并找出它们的中点并记录下来。

(2) 然后根据这些中点来判断有多少个平行四边形,因为只要有两个中点重合,那么就能确定一个平行四边形。

(3) 所以先找出重合中点的个数s,那么它们可以组成的平行四边形个数为C(s,2)。将它们求和即可。

#include<bits/stdc++.h>
using namespace std;
struct node
{
int x,y;
}a[];
int com(int n,int m)
{
int i,s=;
for(i=;i<=m;i++)
s=s*(n+-i)/i;
return s;
}
int main()
{
int n,i,j,s=;
map<pair<int,int>,int>ma;
map<pair<int,int>,int>::iterator it;
cin>>n;
for(i=;i<=n;i++)
scanf("%d%d",&a[i].x,&a[i].y); for(i=;i<=n-;i++)
for(j=i+;j<=n;j++)
ma[make_pair(a[i].x+a[j].x,a[i].y+a[j].y)]++; for(it=ma.begin();it!=ma.end();it++)
s=s+com(it->second,); printf("%d\n",s);
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903