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 
using namespace std;

int main()
{
	int n, a, b, maxn = 0;
	map, int> cnt;
	pair 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;
}

你可能感兴趣的:(枚举,2019icpc徐州,枚举)