您的位置:首页 > 其它

codeforces_660D. Number of Parallelograms

2016-04-16 23:58 316 查看
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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#define Si(a) scanf("%d",&a)
#define Sl(a) scanf("%lld",&a)
#define Sd(a) scanf("%lf",&a)
#define Ss(a) scanf("%s",a)
#define Pi(a) printf("%d\n",(a))
#define Pl(a) printf("%lld\n",(a))
#define Pd(a) printf("%lf\n",(a))
#define Ps(a) printf("%s\n",(a))
#define W(a) while(a--)
#define mem(a,b) memset(a,(b),sizeof(a))
#define FOP freopen("data.txt","r",stdin)
#define inf 0x3f3f3f3f
#define maxn 1000010
#define mod 1000000007
#define PI acos(-1.0)
#define LL long long
using namespace std;

struct point
{
double x,y;
}a[2010],p[4000010];

bool cmp(point a,point b)
{
if(a.x==b.x)return a.y<b.y;
else return a.x<b.x;
}

int main()
{
int i,j,n,top=0;
Si(n);
for(i=0;i<n;i++)
{
Sd(a[i].x),Sd(a[i].y);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
p[top].x=(a[i].x+a[j].x)/2;
p[top].y=(a[i].y+a[j].y)/2;
top++;
}
}
sort(p,p+top,cmp);
LL ans=0;
LL cnt=1;
for(i=0;i<top;i++)
{
if(fabs(p[i].x-p[i+1].x)>=1e-6||fabs(p[i].y-p[i+1].y)>=1e-6)
{
ans+=cnt*(cnt-1)>>1;
cnt=1;
}else
{
cnt++;
}
}
Pl(ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  codeforces