您的位置:首页 > 其它

codeforces 660D. Number of Parallelograms

2016-04-09 10:30 357 查看
D. Number of Parallelograms

time limit per test4 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard 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

4

0 1

1 0

1 1

2 0

output

1

看那些点能组合多少平行四边形,,,,,,

代码:

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct node{
int x,y;
}dian[2020];
struct nn{
int xc,xy;
}bian[2020000];
bool cm(node xx,node yy)
{
if (xx.x==yy.x)
return xx.y<yy.y;
return xx.x<yy.x;
}
bool cmp(nn xx,nn yy)
{
if (xx.xc==yy.xc)
return xx.xy<yy.xy;
return xx.xc<yy.xc;
}
int main()
{
int n;
int k=0,s,kai,lp;
scanf("%d",&n);
for (int i=0;i<n;i++)
scanf("%d%d",&dian[i].x,&dian[i].y);
sort(dian,dian+n,cm);
for (int i=0;i<n-1;i++)
{
for (int j=i+1;j<n;j++)
{
bian[k].xc=dian[j].x-dian[i].x;
bian[k++].xy=dian[j].y-dian[i].y;
}
}
sort(bian,bian+k,cmp);
kai=0;
s=0;
for (int i=1;i<k;i++)
{
if (bian[i].xc!=bian[i-1].xc||bian[i].xy!=bian[i-1].xy)
{
lp=i-kai;
kai=i;
s+=(lp-1)*lp/2;
}
}
printf("%d\n",s/2);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: