zoukankan      html  css  js  c++  java
  • 【POJ 1981 】Circle and Points

    当两个点距离小于直径时,由它们为弦确定的一个单位圆(虽然有两个圆,但是想一想知道只算一个就可以)来计算覆盖多少点。

    #include <cstdio>
    #include <cmath>
    #define N 301
    #define eps 1e-5
    using namespace std;
    int n,ans,tol;
    double x[N],y[N],dx,dy;
    inline double sqr(double x)
    {
        return x*x;
    }
    inline double dis(int a,int b)
    {
        return sqrt((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]));
    }
    inline void solve()
    {
        tol=0;
        for(int i=1; i<=n; i++)
            if(dis(0,i)<=1+eps)
                tol++;
        if(tol>ans)ans=tol;
    }
    inline void get(int a,int b){
        double v=atan((x[b]-x[a])/(y[a]-y[b]));//等于0时会返回inf,v=pi/2
        double c=sqrt(1-sqr(dis(a,b)/2.0));
        dx= c*cos(v);
        dy= c*sin(v);
    }
    int main()
    {
        while(scanf("%d",&n)&&n)
        {
            ans=1;
            for (int i=1; i<=n; i++)
                scanf("%lf%lf",&x[i],&y[i]);
            for (int i=1; i<=n; i++)
                for (int j=i+1; j<=n; j++)
                if(dis(i,j)<2){
                    double mx=(x[i]+x[j])/2.0,my=(y[i]+y[j])/2.0;
                    get(i,j);
                    x[0]=mx+dx,y[0]=my+dy;
                    solve();
                }
            printf("%d
    ",ans);
        }
    }
      
  • 相关阅读:
    docker commit
    镜像原理
    docker command1
    docker镜像命令
    docker work machine
    视图
    后台管理
    模型类
    docker command
    安装virtualenv
  • 原文地址:https://www.cnblogs.com/flipped/p/5722282.html
Copyright © 2011-2022 走看看