The Preliminary Contest for ICPC Asia Xuzhou 2019 Center (map)

You are given a point set with nn 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)(Xc​,Yc​)(not necessarily in the point set), so that for every point (X_i,Y_i)(Xi​,Yi​) in the set, there exists a point (X_j,Y_j)(Xj​,Yj​) (ii can be equal to jj) in the set satisfying X_c=(X_i+X_j)/2Xc​=(Xi​+Xj​)/2 and Y_c=(Y_i+Y_j)/2Yc​=(Yi​+Yj​)/2.

Input

The first line contains an integer n(1 \le n \le 1000)n(1≤n≤1000).

The next nn lines contain nn pair of integers (X_i,Y_i)(Xi​,Yi​) (-10^6 \le X_i,Y_i \le 10^6)(−106≤Xi​,Yi​≤106) -- 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) .

题意: 给出n个点的坐标, 问你最少添加几个点, 使得这些点关于某个中心点的对称,

思路:首先考虑对称中心, 一定是某两个点的对称中心, 否则需要添加更多的点。

所以我们枚举点对, 用map记录, 以某个坐标为中心点的点对有多少, 设中心点坐标为x, y

需要添加的点数自然为n - mp[{ x, y }]。 考虑若当前中心点为输入的n个点之一, 则该点

不需要添加, 自然答案为n - mp[{ x, y }] - 1。 在处理时, 可以先将坐标都乘以2. 这样处理

的坐标都为整数了。

#include <bits/stdc++.h>
//#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#ifdef LOCAL
#define debug(x) cout << "[" __FUNCTION__ ": " #x " = " << (x) << "]\n"
#define TIME cout << "RuningTime: " << clock() << "ms\n", 0
#else
#define TIME 0
#endif
#define hash_ 1000000009
#define Continue(x) { x; continue; }
#define Break(x) { x; break; }
const int N = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
ll fpow(ll a, ll b, int mod) { ll res = 1; for (; b > 0; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; }
int x[1010];
int y[1010];
map<pair<int, int>, int>mp;
map<pair<int, int>, int>vis;
int main()
{
#ifdef LOCAL
	freopen("D:/input.txt", "r", stdin);
#endif
	int n;
	cin >> n;
	int MI = 0x3f3f3f3f;
	if (n == 1)
		cout << "0" << endl, exit(0);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d", &x[i], &y[i]);
		x[i] *= 2;
		y[i] *= 2;
		vis[{x[i], y[i]}] = 1;
	}

	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
		{
			int zx = (x[i] + x[j]) / 2;
			int zy = (y[i] + y[j]) / 2;
			mp[{zx, zy}]++;
		}
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
		{
			int zx = (x[i] + x[j]) / 2;
			int zy = (y[i] + y[j]) / 2;
			if (vis.find({ zx, zy }) != vis.end())
				MI = min(MI, n - mp[{ zx, zy }] * 2 - 1);
			else
				MI = min(MI, n - mp[{ zx, zy }] * 2);
		}
	cout << MI << endl;
	return TIME;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值