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

来源:互联网 发布:淘宝免费注册账号申请 编辑:程序博客网 时间:2024/05/27 10:44
CodeForces - 660D
Number of Parallelograms
Time Limit: 4000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u

Submit 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
40 11 01 12 0
Output
1

Source

Educational Codeforces Round 11
//题意:
给你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 1000000007using 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;}

0 0
原创粉丝点击