zoukankan      html  css  js  c++  java
  • HDU 4173(计算几何

    题意:给出若干个点,求半径为2.5的圆最多包含多少个点。

    思路:查到的一篇题解是枚举三个点的外接圆,这个对于我等计算几何小白来说还是不太好做。。。。后来听大神讲的,因为半径已知,所以只需要枚举经过两点的半径为2.5的所有圆就好(两个点对应两个圆),这样不仅好写,而且复杂度也降低了。

    (感觉不用一大串模板都不好意思叫计算几何了。。。。。)

    #include<iostream>
    #include<map>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<vector>
    #include<queue>
    #include<stack>
    #include<functional>
    #include<set>
    #include<cmath>
    #define pb push_back
    #define fs first
    #define se second
    #define sq(x) (x)*(x)
    #define eps 0.0000000001
    using namespace std;
    typedef long long ll;
    typedef pair<ll,ll> P;
    const int maxv=250;
    double x[maxv],y[maxv];
    int n;
    double cycx[maxv*maxv+30];
    double cycy[maxv*maxv+30];
    int cych=0;
    double dis(double x1,double y1,double x2,double y2){
        return sqrt(sq(x1-x2)+sq(y1-y2));
    }
    void getcenter(double x1,double y1,double x2,double y2){
        double mx=(x1+x2)/2,my=(y1+y2)/2;
        double k=(y1-y2)/(x1-x2);
        k=-1/k;
        if(x1-x2==0) k=0;
        double dis1=dis(x1,y1,x2,y2);
        dis1/=2;
        double dis2=sqrt(sq(2.5)-sq(dis1));
        double dx1=1./sqrt(1+k*k)*dis2,dy1=k/sqrt(1+k*k)*dis2;
        double dx2=-dx1,dy2=-dy1;
        cycx[cych++]=mx+dx1,cycy[cych-1]=my+dy1;
        cycx[cych++]=mx+dx2,cycy[cych-1]=my+dy2;
    }
    int main(){
        freopen("/home/files/CppFiles/in","r",stdin);
    /*    std::ios::sync_with_stdio(false);
        std::cin.tie(0);*/
        while(cin>>n){
            for(int i=0;i<n;i++) scanf("%lf%lf",x+i,y+i);
            cych=0;
            for(int i=0;i<n;i++){
                for(int j=i+1;j<n;j++){
                    if(dis(x[i],y[i],x[j],y[j])<5+eps);
                    getcenter(x[i],y[i],x[j],y[j]);
                }
            }
            int ans=1;
            for(int i=0;i<cych;i++){
                int cont=0;
                for(int j=0;j<n;j++){
                    if(dis(x[j],y[j],cycx[i],cycy[i])<2.5+eps){
                        cont++;
                    }
                }
                ans=max(ans,cont);
            }
            cout<<ans<<endl;
        }
        return 0;
    }
    View Code
  • 相关阅读:
    文件的类型
    读取文件,并按原格式输出文件内容的三种方式
    react hook代码框架
    器具的行为模式
    设计模式
    cpu 内存 机器语言 汇编 高级语言 平台之间的关系
    操作系统之内存
    操作系统之文件
    操作系统之IO
    七层模型之应用层
  • 原文地址:https://www.cnblogs.com/Cw-trip/p/4676880.html
Copyright © 2011-2022 走看看