平行四边形数

Accept: 18    Submit: 35
Time Limit: 2000 mSec    Memory Limit : 32768 KB

Problem Description

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

Input

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

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

Output

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

Sample Input

4 0 1 1 0 1 1 2 0

Sample Output

1

Source

福州大学第十三届程序设计竞赛
 
平形四边形对角顶点所对应中点相等, 所以排序即可求解;
#include <cstdio>
#include <algorithm>
const int N = 501;
struct para
{
    int x, y, nx, ny;
} cc[N], ncc[N*N];

using namespace std;
bool cmp(para a, para b)
{
    if(a.nx == b.nx)
        return a.ny < b.ny;
    return a.nx < b.nx;
}
int main()
{
    int n;
    while(scanf("%d", &n) != EOF)
    {
        for(int i=0; i< n; i++)
        {
            scanf("%d%d", &cc[i].x, &cc[i].y);
        }
        int cnt= 0;
        for(int i=0; i<n-1; i++)
            for(int j=i+1; j< n; j++)
            {
                ncc[cnt].nx =cc[i].x+ cc[j].x;
                ncc[cnt].ny =cc[i].y+ cc[j].y;
                cnt++;
            }
        sort(ncc, ncc+cnt, cmp);
        int ccnt =0;
        int sum = 0;
        for(int i=1; i< cnt; i++)
        {
            if(ncc[i].nx ==ncc[i-1].nx && ncc[i].ny== ncc[i-1].ny)
                ++ccnt;
            else
            {
                sum= sum+((1+ccnt)*ccnt/2);
                ccnt=0;
            }
        }
        printf("%d\n", sum);
    }
    return 0;
}

 

 
posted on 2016-05-03 15:12  cleverbiger  阅读(198)  评论(0)    收藏  举报