K- Center
2000ms
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) .
1 #include <bits/stdc++.h> 2 #pragma GCC optimize(3) 3 using namespace std; 4 typedef long long ll; 5 typedef pair<int,int> PII; 6 const int maxn=1e6+7; 7 map<PII,int>MAP; 8 int x[maxn],y[maxn]; 9 int main() 10 { 11 int n; 12 int ans=0; 13 scanf("%d",&n); 14 for(int i=1;i<=n;++i) 15 { 16 scanf("%d%d",&x[i],&y[i]); 17 x[i]*=2; 18 y[i]*=2; 19 } 20 for(int i=1;i<=n;++i) 21 { 22 for(int j=1;j<=n;++j) 23 { 24 int a=++MAP[PII((x[i]+x[j])/2,(y[i]+y[j])/2)]; 25 if(a>ans)ans=a; 26 } 27 } 28 printf("%d ",n-ans); 29 return 0; 30 }