zoukankan      html  css  js  c++  java
  • 圆---已经两点及其半径求圆心

      UVALive - 6477

    /*  gyt
           Live up to every day            */
    #include<cstdio>
    #include<cmath>
    #include<iostream>
    #include<algorithm>
    #include<vector>
    #include<stack>
    #include<cstring>
    #include<queue>
    #include<set>
    #include<string>
    #include<map>
    #include <time.h>
    #define PI acos(-1)
    using namespace std;
    typedef long long ll;
    typedef double db;
    const int maxn = 30+10;
    const ll maxm = 1e7;
    const int modd = 10000007;
    const int INF = 1<<30;
    const db eps = 1e-8;
    struct point {
        double x, y;
    }p[maxn], a1, a2;
    db r;
    int n;
    
    int sgn(db x) {
        return x<-eps?-1:x<eps?0:1;
    }
    double dis(point a,point b)    {
        return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
    }
    void look_center(point a,point b)  {
        point aa,bb,mid;
        aa.x = b.x-a.x;
        aa.y = b.y-a.y;
        mid.x = (a.x+b.x)/2.0;
        mid.y = (a.y+b.y)/2.0;
        double dist = dis(a,mid);
        double c = sqrt(r*r-dist);
        if (a.y==b.y) {
            a1.x=mid.x;  a1.y=mid.y+c;
            a2.x=mid.x;  a2.y=mid.y-c;
            return;
        }
        double ang = atan(-aa.x/aa.y);
        a1.x = mid.x + c*cos(ang);
        a1.y = mid.y + c*sin(ang);
        a2.x = mid.x - c*cos(ang);
        a2.y = mid.y - c*sin(ang);
    }
    void solve() {
        scanf("%lf%d", &r, &n);
        for (int i=0; i<n; i++) {
            scanf("%lf%lf", &p[i].x, &p[i].y);
        }
        int ans=1;
        if (n<=1)  printf("%d
    ", n);
        else {
            for (int i=0; i<n; i++) {
                for (int j=i+1; j<n; j++) {
                    if (dis(p[i], p[j])>4.0*r*r)  continue;
                     look_center(p[i], p[j]);
                    int num=0;
                    for (int k=0; k<n; k++) {
                        if (sgn(dis(a1, p[k])-r*r)<=0)  num++;
                    }
                    ans=max(ans, num);
                    num=0;
                    for (int k=0; k<n; k++) {
                        if (sgn(dis(a2, p[k])-r*r)<=0)  num++;
                    }
                    ans=max(ans, num);
                }
            }
            cout<<ans<<endl;
        }
    }
    
    int main() {
        int t = 1;
        //freopen("in.txt","r",stdin);
      //  freopen("gcd.out","w",stdout);
        scanf("%d", &t);
        while(t--)
            solve();
        return 0;
    }
  • 相关阅读:
    pat1038. Recover the Smallest Number (30)
    pat1037. Magic Coupon (25)
    pat1036. Boys vs Girls (25)
    pat1031. Hello World for U (20)
    pat1030. Travel Plan (30)
    pat1028. List Sorting (25)
    pat1027. Colors in Mars (20)
    pat1017. Queueing at Bank (25)
    pat1025. PAT Ranking (25)
    Reverse Linked List II
  • 原文地址:https://www.cnblogs.com/gggyt/p/7217569.html
Copyright © 2011-2022 走看看