2020 Niuke Summer Multi-School Training Camp (Second Session) B Boundary

2020/7/14
two methods are used here:

  • The circle of the known answer crosses the origin, so the final vertical bisector between the point on the circle and the origin must cross the center of the circle. The vertical bisector between n points and the origin is calculated. There are n*(n -1)/2 intersection points. Find the number of times that a certain point appears the most among these n*(n-1)/2 points. The number of times is the answer (because the same intersection of the vertical bisectors means that the centers of the circles coincide and the circles pass the origin, so they are in the same circle ).
    The process of deriving the intersection point is not complicated. Finally, the simultaneous equations are solved twice to solve the coordinates (xi, yi) of the intersection point, (don't bring x into the vertical bisector to find y, which is more troublesome).
    Code:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const int maxn=2e3+9;
typedef pair<double,double> pdd;
int n;
double x[maxn],y[maxn];
map<pdd,int> res;
int main(){
    
    
    scanf("%d",&n);
    rep(i,0,n) scanf("%lf%lf",x+i,y+i);
    int ans=0;
    rep(i,0,n) {
    
    
        res.clear();
        rep(j,i+1,n){
    
    
            if(x[i]*y[j]==x[j]*y[i]) continue;
            double d=x[i]*y[j]-x[j]*y[i],d1=x[i]*x[i]+y[i]*y[i],d2=x[j]*x[j]+y[j]*y[j];
            double X=(y[i]*d2-y[j]*d1)/d,Y=(x[i]*d2-x[j]*d1)/d;
            ans=max(ans,++res[{
    
    X,Y}]);
        }
    }
    printf("%d\n",ans+1);
}
  • The second approach is given by the solution:
    Insert picture description here
    code:
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
const double eps = 1e-15;
const int N = 2010;
int X[N], Y[N];
double A[N];
int Cross(int lhs, int rhs) {
    
     // 向量叉积
    return X[lhs] * Y[rhs] - X[rhs] * Y[lhs];
}
int Dis2(int lhs, int rhs) {
    
     // 两点欧氏距离的平方
    int dx = X[lhs] - X[rhs], dy = Y[lhs] - Y[rhs];
    return dx * dx + dy * dy;
}
double GetCosAngle2(int i, int j) {
    
     // Oi对角的cos值
    int a2 = Dis2(0, i), b2 = Dis2(i, j), c2 = Dis2(0, j);
    return (double)(b2 + c2 - a2) / 2 / sqrt(b2) / sqrt(c2);
}
 
int main()
{
    
    
    int n, ans = 1;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d%d", X + i, Y + i);
    for (int i = 1; i <= n; i++) {
    
    
        int cnt = 0;
        for (int j = 1; j <= n; j++) if (Cross(i, j) < 0) A[++cnt] = GetCosAngle2(i, j);
        sort(A + 1, A + cnt + 1);
        for (int l = 1, r; l <= cnt; l = r) {
    
    
            for (r = l; fabs(A[l] - A[r]) < eps && r <= cnt; r++);
            ans = max(ans, r - l + 1);
        }
    }
    printf("%d\n", ans);
    return 0;
}

Guess you like

Origin blog.csdn.net/ylwhxht/article/details/107454531