zoukankan      html  css  js  c++  java
  • Circle and Points

    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    
    struct Point
    {
        double x,y;
        Point() {};
        Point(int _x,int _y):x(_x),y(_y) {};
    } p[400];
    
    double dis(Point a,Point b)
    {
        return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    }
    
    struct node
    {
        double angle;
        bool in;
    } a[180000];
    int n,cnt;
    
    bool cmp(node a,node b)
    {
        return a.angle!=b.angle?a.angle<b.angle:a.in>b.in;
    }
    
    void MaxCircleCover()
    {
        int ans=1;
        for (int i=1; i<=n; i++)
        {
            int cnt=0;
            for (int j=1; j<=n; j++)
            {
                if (i==j||dis(p[i],p[j])>2.0)
                {
                    continue;
                }
                double angle=atan2(p[i].y-p[j].y,p[i].x-p[j].x);
                double phi=acos(dis(p[i],p[j])/2);
                a[cnt].angle=angle-phi;
                a[cnt++].in=1;
                a[cnt].angle=angle+phi;
                a[cnt++].in=0;
            }
            sort(a,a+cnt,cmp);
            int tmp=1;
            for (int i=0; i<cnt; i++)
            {
                if (a[i].in)
                {
                    tmp++;
                }
                else
                {
                    tmp--;
                }
                ans=max(ans,tmp);
            }
        }
        printf("%d
    ",ans);
    }
    
    int main()
    {
        while (scanf("%d",&n),n)
        {
            for (int i=1; i<=n; i++)
            {
                scanf("%lf%lf",&p[i].x,&p[i].y);
            }
            MaxCircleCover();
        }
        return 0;
    }
    

      

  • 相关阅读:
    关系运算符重载
    一元运算符重载
    二元运算符重载
    重载函数和重载运算符
    Linux之文件通信
    Linux进程通信之mmap
    Linux之创建多个子进程
    内联函数
    静态成员
    this指针
  • 原文地址:https://www.cnblogs.com/Accpted/p/11263029.html
Copyright © 2011-2022 走看看