平行四边形数

来源:互联网 发布:linux 设置代理服务器 编辑:程序博客网 时间:2024/05/01 13:19

平行四边形数Crawling in process...   

   Crawling failed Time Limit:2000MS    Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

SubmitStatus

Description

在一个平面内给定n个点,任意三个点不在同一条直线上,用这些点可以构成多少个平行四边形?一个点可以同时属于多个平行四边形。

Input

多组数据(<=10),处理到EOF。

每组数据第一行一个整数n(4<=n<=500)。接下来n行每行两个整数xi,yi(0<=xi,yi<=1e9),表示每个点的坐标。

Output

每组数据输出一个整数,表示用这些点能构成多少个平行四边形。

Sample Input

40 11 01 12 0

Sample Output

1

 

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef struct p{double x, y;}point;point a[505];point zd[250005];bool cmp(point v,point u){if(v.x == u.x) return v.y > u.y;return v.x > u.x;}int main(){int n, r;int ans, cnt;while(scanf("%d",&n) != EOF){r = 0;ans = 0;for(int i = 0;i < n;i ++)cin>>a[i].x>>a[i].y;for(int i = 0;i < n;i ++)for(int j = i + 1;j < n;j ++){zd[r].x = (a[i].x + a[j].x) / 2;zd[r ++].y = (a[i].y + a[j].y) / 2;}sort(zd,zd+r-1,cmp);point t = zd[0];cnt = 1;for(int i = 1;i < r;i ++){if(t.x == zd[i].x && t.y == zd[i].y)cnt ++;else{ans += cnt * (cnt -1) / 2;cnt = 1;t = zd[i];}}printf("%d\n",ans);}return 0;}


 

0 0