CodeForces 660D Number of Parallelograms

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<memory.h>
#include<functional>
#include<limits.h>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
using namespace std;
const int maxn = 2005;
struct point {
	int x, y;
	point(int x1 = 0, int y1 = 0) :x(x1), y(y1) {}
}p[maxn];

struct vec {
	int x, y;
	vec(int x1, int y1) :x(x1), y(y1) {}
	bool operator==(const vec& v) const {
		return x == v.x && y == v.y;
	}
	bool operator<(const vec& v) const {
		if (x == v.x)
			return y < v.y;
		return x < v.x;
	}
};

int main() {
	int n;
	while (cin >> n) {
		for (int i = 0; i < n; ++i) {
			cin >> p[i].x >> p[i].y;
		}
		map<vec, int> mp;
		
		for (int i = 0; i < n; ++i) {
			for (int j = i + 1; j < n; ++j) {
				int x = p[i].x - p[j].x;
				int y = p[i].y - p[j].y;
				if (x < 0)
					x = -x, y = -y;
				if (x == 0 && y < 0)
					y = -y;
				vec temp1(x, y);
				mp[temp1]++;
			}
		}
		bool ok = false;
		long long cnt = 1;
		map<vec, int>::iterator it;
		for (it = mp.begin(); it != mp.end(); ++it) {
			if (it->second >= 2) {
				ok = true;
				cnt += it->second * (it->second-1) / 2;
			}
		}
		if (ok)
			cout << cnt/2 << endl;
		else
			cout << 0 << endl;
	}

	return 0;
}

暴力枚举,找到一组相等的向量→肯定可以构成一个平行四边形(肯定还会出现它的另一对边,这里相当于多算了一次,故最后结果除以2)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值