Problem 2231 平行四边形数 fzoj

校赛中遇到了,但是没有做出来…

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

开始自己做题的时候就想到了证明两组边对应相等,然后呢,没有考虑到 还有等腰梯形这种情况,自己在测试样例的时候又刚好没想到这组数据,就一直在那儿wawawa,wa的快哭了。

下来后说是福oj的一道题,就找出来Ac掉,是看的别人的想法,找出有相同中点的线段,然后排列组合

#include <stdio.h>
#include <algorithm>
using namespace std;
typedef struct{
    double x, y;
}P;
P d[1000000];
bool com(P a, P b){
    if(a.x < b.x) return true;
    if(a.x==b.x&&a.y<b.y) return true;
    return false;
}
int main(){
    int n, s;
    while(scanf("%d", &n)!=EOF){
        s = 0;
        P p[505];
        for(int i=0; i<n; i++){
            scanf("%lf%lf", &p[i].x, &p[i].y);
        }
        int m = 0;
        for(int i=0; i<n; i++){
            for(int j=i+1; j<n; j++){ //如果有相同的再进行排列组合  
                d[m].x = (p[i].x+p[j].x) / 2;
                d[m++].y = (p[i].y+p[j].y) / 2;
            }
        }
        int s = 0;
        sort(d, d+m, com);
        P t = d[0];
        int count = 1;
        for(int i=1; i<m; i++){
            if(t.x==d[i].x&&t.y==d[i].y) count++;
            else{
                s += count*(count-1) / 2;
                count = 1;
                t = d[i];
            }
        }
        printf("%d\n", s);
    }
    return 0;
}

第一次写博客 哈哈哈.

猜你喜欢

转载自blog.csdn.net/zf2015800505/article/details/78455375