CodeForces 660D. Number of Parallelograms【模拟】

来源:互联网 发布:js跳转页面地址栏不变 编辑:程序博客网 时间:2024/06/05 18:19
D. Number of Parallelograms
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Example
input
40 11 01 12 0
output
1
AC-code:
<pre name="code" class="cpp">#include<cstdio>#include<algorithm>using namespace std;struct node{int x,y;}s[2005],p[2005*2005];bool cmp(node a,node b){if(a.x==b.x)return a.y>b.y;return a.x>b.x;}int main(){int n,i,j,t,k,sum;scanf("%d",&n);for(i=0;i<n;i++)scanf("%d%d",&s[i].x,&s[i].y);sort(s,s+n,cmp);for(t=0,i=0;i<n-1;i++)for(j=i+1;j<n;j++){p[t].x=s[i].x-s[j].x;p[t++].y=s[i].y-s[j].y;}sort(p,p+t,cmp);sum=0;for(i=1,k=0;i<t;i++){if(p[i-1].x==p[i].x&&p[i].y==p[i-1].y)continue;else{sum+=(i-k-1)*(i-k)/2;k=i;}}sum+=(i-k-1)*(i-k)/2;printf("%d\n",sum/2);return 0;}


0 0