平行四边形数

来源:互联网 发布:js超过一行显示省略号 编辑:程序博客网 时间:2024/05/01 08:22

在一个平面内给定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;struct node{    int x,y;};bool cmp(node n,node m){    if(n.y==m.y)        return n.x<m.x;    return n.y<m.y;}int main(){    node std[1000],std1[250000];    int n,m,i,j,k,t;    while(scanf("%d",&n)!=EOF)    {        for(i=0; i<n; i++)        {            scanf("%d %d",&std[i].x,&std[i].y);        }        for(i=0,k=0; i<n; i++)        {            for(j=i+1; j<n; j++)            {                std1[k].x=std[i].x+std[j].x;                std1[k].y=std[i].y+std[j].y;                k++;            }        }        sort(std1,std1+k,cmp);        int ans=1;        node pe=std1[0];        int sum=0;        for(i=1; i<k; i++)        {            if(std1[i].x==pe.x&&std1[i].y==pe.y)            {                ans++;            }            else            {                sum+=(ans-1)*ans/2;                pe=std1[i];                ans=1;            }        }        printf("%d\n",sum);    }    return 0;}


原创粉丝点击