Center
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) .
暴力枚举每个可能的中心,得到以该位置为中心的点对的个数。找出点最多的中心,答案即为点的总数减去以该中心为中心的点的个数。复杂度为O(n^2)。
#include <bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 1e3;
struct Point
{
int x, y;
Point() {}
Point(int x, int y): x(x), y(y) {}
bool operator < (const Point& p) const
{
if(x != p.x)
return x < p.x;
return y < p.y;
}
}p[maxn];
int n;
map<Point, int> m;
void read()
{
cin >> n;
int x, y;
for(int i = 0; i < n; ++i)
{
cin >> x >> y;
p[i] = Point(x<<1, y<<1);
}
}
void solve()
{
int ans = 0;
for(int i = 0; i < n; ++i)
{
for(int j = 0; j < n; ++j)
{
Point pc = Point((p[i].x+p[j].x)>>1, (p[i].y+p[j].y)>>1);
if(!m.count(pc))
m[pc] = 1;
else
++m[pc];
ans = max(m[pc], ans);
}
}
cout << n - ans << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
read();
solve();
return 0;
}