zoukankan      html  css  js  c++  java
  • 牛客多校第二场 B Boundary

    牛客多校第二场 B

    链接:https://ac.nowcoder.com/acm/contest/5667/B

    题目描述

    Given (n) points in 2D plane. Considering all circles that the origin point ((0, 0)) is on their boundries, find the one with the maximum given points on its boundry. Print the maximum number of points.

    输入描述:

    The first line contains one integer (n~(1 leq n leq 2000)) , denoting the number of given points.
    Following (n) lines each contains two integers (x, y~(|x|,|y| leq 10000)), denoting a given point ((x, y)).
    It's guaranteed that the points are pairwise different and no given point is the origin point.

    输出描述:

    Only one line containing one integer, denoting the answer.

    输入

    4
    1 1
    0 2
    2 0
    2 2
    

    输出

    3
    

    说明

    Considering circle ((x-1)^2+(y-1)^2=2), we can see that the origin point is on its boundry and that there are (3) given points ({(0,2),(2,0),(2,2)}) on its boundry.

    img

    题解

    题意

    在一个二维平面中,给 (n) 个点,以 ((x,y)) 为圆心的圆经过 ((0,0)) 点,问,这个圆在这 (n) 个点中最多能经过多少个点。

    思路

    对于两个不同的点 ((a_i,b_i))((a_j,b_j)) ,还有额外加的一个 ((0,0)) 点在三点不共线的条件下,一定可以确定一个圆,并且可以求出圆心,

    [(x-a_i)^2+(y-b_i)^2=x^2+y^2 \ (x-a_j)^2+(y-b_j)^2=x^2+y^2 \ (x-a_i)^2+(y-b_i)^2=(x-a_j)^2+(y-b_j)^2 ]

    化简式子,可以得到一个关于 $x,y $ 的方程组

    [y=a_j(a_i^2+b_i^2)-a_i(a_j^2+b_j^2)/(2(b_ia_j-a_ib_j)) \ y=b_j(a_i^2+b_i^2)-b_i(a_j^2+b_j^2)/(2(b_ia_j-a_ib_j)) ]

    之后进行求解储存数据即可。

    注意

    • (map) 会卡 (tle)
    • 卡精度,能不使用 (double) 尽量不要使用 (double)
    • 当三点共线时,不进行考虑

    代码

    #pragma GCC optimize(3)
    #include <cmath>
    #include <vector>
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    typedef long long ll;
    const int maxn = 2e3+55;
    const double eps = 1e-7;
    struct Point{double x,y;};
    bool cmp(Point x,Point y){if(eps>fabs(x.x-y.x))return x.y<y.y;return x.x<y.x;}
    struct node{ll a,b;ll aa,bb;}nn[maxn];
    vector<Point>v;
    int main(){
        int n;
        int maxxx=0;
        scanf("%d",&n);
        if(n==1){printf("1
    ");return 0;}
        for(int i=0;i<n;++i){
            v.clear();
            scanf("%lld%lld",&nn[i].a,&nn[i].b);
            nn[i].aa=nn[i].a*nn[i].a;
            nn[i].bb=nn[i].b*nn[i].b;
            for(int j=0;j<i;++j){
                if(nn[i].b*nn[j].a==nn[j].b*nn[i].a)continue;
                ll yx=nn[j].a*(nn[i].aa+nn[i].bb)-nn[i].a*(nn[j].aa+nn[j].bb);
                ll yy=(ll)2*(nn[i].b*nn[j].a-nn[j].b*nn[i].a);
                ll xx=nn[j].b*(nn[i].aa+nn[i].bb)-nn[i].b*(nn[j].aa+nn[j].bb);
                ll xy=-yy;
                v.push_back({(double)xx/xy,(double)yx/yy});
            }
            int maxx=0,ans=1;
            sort(v.begin(),v.end(),cmp);
            for(int j=1;j<(int)v.size();++j){
                if(fabs(v[j].y-v[j-1].y)<eps&&fabs(v[j].x-v[j-1].x)<eps)ans++;
                else ans=1;
                maxx=max(maxx,ans);
            }
            maxxx=max(maxxx,maxx+1);
        }
        printf("%d
    ",maxxx);
        return 0;
    }
    
    新赛季的开始
  • 相关阅读:
    ORA-01439: column to be modified must be empty to change datatype
    解决rhel相关系统下yum找不到安装包的解决方法
    oracle的function和procedure返回值给shell
    [摘] SQLPLUS Syntax
    Unix/Linux中shell调用sqlplus的方式
    sqlplus连接数据库的4种方式
    shell调用sqlplus批量执行sql文件
    shell自定义函数
    Java创建Oracle数据库表
    TCP的三次握手(建立连接)和四次挥手(关闭连接)
  • 原文地址:https://www.cnblogs.com/VagrantAC/p/13295083.html
Copyright © 2011-2022 走看看