• POJ 1981 Circle and Points 单位圆覆盖


    枚举两点,算出圆心,枚举其他点...加个优化就2MS水过了...

    /********************* Template ************************/
    #include <set>
    #include <map>
    #include <list>
    #include <cmath>
    #include <ctime>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <bitset>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cassert>
    #include <cstdlib>
    #include <cstring>
    #include <sstream>
    #include <fstream>
    #include <numeric>
    #include <iomanip>
    #include <iostream>
    #include <algorithm>
    #include <functional>
    using namespace std;
    #define BUG         cout<<" BUG! "<<endl;
    #define LINE        cout<<" ------------------ "<<endl;
    #define FIN         freopen("in.txt","r",stdin);
    #pragma comment     (linker,"/STACK:102400000,102400000")
    template<class T> inline T L(T a)       {return (a << 1);}
    template<class T> inline T R(T a)       {return (a << 1 | 1);}
    template<class T> inline T lowbit(T a)  {return (a & -a);}
    template<class T> inline T Mid(T a,T b) {return ((a + b) / 2);}
    template<class T> inline T gcd(T a,T b) {return b ? gcd(b,a%b) : a;}
    template<class T> inline T lcm(T a,T b) {return a / gcd(a,b) * b;}
    template<class T> inline T Min(T a,T b) {return a < b ? a : b;}
    template<class T> inline T Max(T a,T b) {return a > b ? a : b;}
    template<class T> inline T Min(T a,T b,T c)     {return min(min(a,b),c);}
    template<class T> inline T Max(T a,T b,T c)     {return max(max(a,b),c);}
    template<class T> inline T Min(T a,T b,T c,T d) {return min(min(a,b),min(c,d));}
    template<class T> inline T Max(T a,T b,T c,T d) {return max(max(a,b),max(c,d));}
    template<class T> inline void mem(T &a,int b)   {memset(a,b,sizeof(a));}
    template<class T> inline T exGCD(T a, T b, T &x, T &y){ //
        if(!b) return x = 1, y = 0, a;
        T res = exGCD(b, a % b, x, y), tmp = x;
        x = y, y = tmp - (a / b) * y; return res;
    }
    typedef long long LL;    typedef unsigned long long ULL;
    //typedef __int64 LL;      typedef unsigned __int64 ULL;
    const LL LINF   = 1LL << 60;
    const int MOD   = 1000000007;
    const int INF   = 0x7fffffff;
    const int MAXN  = 300+5;//100000+5;
    const double EPS    = 1e-8;
    const double DINF   = 1e15;
    const double PI     = acos(-1.0);
    
    /*********************   By  F   *********************/
    struct POINT {
        double x,y;
        POINT(double _x = 0,double _y = 0){x = _x, y = _y;}
    }p[MAXN];
    struct CIRCLE {
        double r;
        POINT o;
        CIRCLE(double _r = 0 , POINT _o = 0){r = _r, o = _o;}
    };
    double dist(POINT p1,POINT p2){
        return sqrt((p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y));
    }
    bool incir(POINT a ,CIRCLE b){
        if((a.x - b.o.x) * (a.x - b.o.x) + (a.y - b.o.y) * (a.y - b.o.y) - 1 <= EPS) return true;
        return false;
    }
    POINT get_p(POINT p1,POINT p2){
        POINT tmp = POINT(Mid(p1.x,p2.x),Mid(p1.y,p2.y));
        double angle = atan2(p1.x - p2.x,p2.y - p1.y);
        double dis = sqrt(1 - dist(p1,tmp) * dist(p1,tmp));
        return POINT(tmp.x + dis * cos(angle),tmp.y + dis * sin(angle));
    }
    int n ;
    int main(){
        //FIN
        while(scanf("%d",&n)!=EOF && n){
            for(int i = 0 ; i < n ; i++)
               scanf("%lf%lf",&p[i].x,&p[i].y);
            int cnt = 1;
            for(int i = 0 ; i < n ; i++){
                for(int j = i + 1 ; j < n ; j++){
                    if(dist(p[i],p[j]) > 2.0) continue;
                    CIRCLE c = CIRCLE(1.0,get_p(p[i],p[j]));
                    int cc = 0;
                    for(int k = 0 ; k < n ; k++)
                        if(incir(p[k],c)) cc++;
                    cnt = Max(cnt,cc);
                }
            }
            printf("%d
    ",cnt);
        }
        return 0;
    }
  • 相关阅读:
    对Spring Boot 及Mybatis简单应用
    云时代架构读后感(十)
    云时代架构读后感(九)
    云时代架构读后感(八)
    云时代架构读后感(七)
    云时代架构读后感(六)
    关于mysql,sqlserverl,与oracle数据库连接总结
    云时代架构读后感(五)
    javaweb实现添加课程
    javaweb入门(使用SQLserver2008 R2数据库)
  • 原文地址:https://www.cnblogs.com/Felix-F/p/3303120.html
Copyright © 2020-2023  润新知