FZU 2231 平行四边形数

Problem 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

题目解法:求出任意两个点的中点,因为题目中已经表明任意三个点不在一条直线上,所以中点相同的点中任选两个都能组成平行四边形, C(n,2).


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <cmath>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <set>
#define pi acos(-1.0)
#define LL long long
#define ULL unsigned long long
#define inf 0x3f3f3f3f
#define INF 1e18
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define debug(a) printf("---%d---\n", a)
#define mem0(a) memset(a, 0, sizeof(a))
#define memi(a) memset(a, inf, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
using namespace std;
typedef pair<int, int> P;
const double eps = 1e-10;
const int maxn = 1e6 + 5;
const int mod = 1e8;

struct Point{
    double x, y;
}p[505];
Point mid[maxn];
int cmp(Point a, Point b){
    if (a.x != b.x) return a.x < b.x;
    return a.y < b.y;
}
int main(void)
{
//	freopen("C:\\Users\\wave\\Desktop\\NULL.exe\\NULL\\in.txt","r", stdin);
    int n, i, j;
    while (cin >> n){
        for (i = 1; i <= n; i++)
            scanf("%lf %lf", &p[i].x, &p[i].y);
        int cnt = 0;
        for (i = 1; i <= n; i++){
            for (j = i+1; j <= n; j++){
                mid[++cnt].x = p[i].x / 2 + p[j].x / 2;
                mid[cnt].y = p[i].y / 2 + p[j].y / 2;
            }
        }
        sort(mid+1, mid+1+cnt, cmp);
        double curx = mid[1].x;
        double cury = mid[1].y;
        int curt = 1, ans = 0;
        for (i = 2; i <= cnt; i++){
            if (mid[i].x == curx && mid[i].y == cury)
                curt++;
            else {
                ans += (curt-1)*curt/2;
                curx = mid[i].x;
                cury = mid[i].y;
                curt = 1;
            }
        }
        cout << ans << endl;
    }

	return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值