2019icpc 徐州网络赛 K.Center (枚举)

You are given a point set with n points on the 2D-plane, your task is to find the smallest number of points you need to add to the point set, so that all the points in the set are center symmetric.

All the points are center symmetric means that you can find a center point (X_c,Y_c)(not necessarily in the point set), so that for every point (X_i,Y_i)in the set, there exists a point (X_j,Y_j)(i can be equal to j) in the set satisfying X_c=(X_i+X_j)/2 and
Y_c = Y_i+Y_j)/2

Input
The first line contains an integer n(1≤n≤1000).
The next nn lines contain nn pair of integers (X_i,Y_i)(−10^6≤Xi ,Yi ≤10^6) – the points in the set

Output
Output a single integer – the minimal number of points you need to add.

样例输入
3
2 0
-3 1
0 -2
样例输出
1
样例解释
For sample 11, add point (5,-3)(5,−3) into the set, the center point can be (1,-1)(1,−1) .

solution:枚举每两个点得中点,当该中点的存在次数最多,答案即n-该次数

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n, a, b, maxn = 0;
	map<pair<int, int>, int> cnt;
	pair<int, int> point[1000];
	scanf("%d", &n);
	for (int i = 0; i < n; ++i){
		scanf("%d%d", &a, &b);
		point[i] = make_pair(a << 1, b << 1);//以免后面求中点时产生误差
	}
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < n; ++j){
			a = point[i].first + point[j].first >> 1;
			b = point[i].second + point[j].second >> 1;
			++cnt[make_pair(a, b)];
			maxn = max(maxn, cnt[make_pair(a, b)]);
		}
	}
	printf("%d\n", n - maxn);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值