zoukankan      html  css  js  c++  java
  • Codeforces Round #465 &935C. Fifa and Fafa计算几何

    传送门

    题意:在平面中,有一个圆,有一个点,问能在这个圆中围出最大的圆的圆心坐标和半径。要求这个最大圆不包含这个点。

    思路:比较基础的计算几何,要分三种情况,第一种就是这个点在圆外的情况。第二种是点在圆内。第三种是这个点和圆心重合。

    ac代码

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <string>
    #include <vector>
    #include <map>
    #include <set>
    #include <queue>
    #include <list>
    #include <iterator>
    #include <cmath>
    using namespace std;
    
    #define lson (l , mid , rt << 1)
    #define rson (mid + 1 , r , rt << 1 | 1)
    #define debug(x) cerr << #x << " = " << x << "
    ";
    #define pb push_back
    #define pq priority_queue
    
    #define Pll pair<ll,ll>
    #define Pii pair<int,int>
    
    #define fi first
    #define se second
    
    #define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
    typedef long long ll;
    typedef unsigned long long ull;
    const double espp = 0.0000000001;
    
    /*-----------------show time----------------*/
    double R,x,y,x2,y2;
    double dis(double a,double b,double x,double y)
    {
        return sqrt((a-x)*(a-x) + (b-y)*(b-y));
    }
    int main(){
        scanf("%lf%lf%lf%lf%lf", &R, &x, &y, &x2, &y2);
        double d = dis(x,y,x2,y2);
        
        if(d > R ||abs(d-R) < espp)
        {
            printf("%lf %lf %lf
    ",x,y,R);
        }
        else
        {
            double r1 = (R + d)/2;  
            double dx = 1.0*(x-x2)*(x-x2) + 1.0*(y-y2)*(y-y2);
            dx = sqrt(dx);  
            double ans1,ans2;
            if(dx!=0)
            {
                 ans1 = x2 + (x-x2)/dx*r1;
                 ans2 = y2 + (y-y2)/dx*r1;
            }
            else 
            {            
                ans1 = x;
                ans2 = y+R/2; 
            }
            printf("%.9lf %.9lf %.9lf
    ",ans1,ans2,r1);
        }
        
        
        return 0;
    }
    CF935C
  • 相关阅读:
    POJ 1113 Wall
    POJ 3525 Most Distant Point from the Sea
    POJ 3335 Rotating Scoreboard
    POJ 1228 Grandpa's Estate
    POJ 1873 The Fortified Forest
    POJ 2354 Titanic
    POJ 3130 How I Mathematician Wonder What You Are!
    POJ 1106 Transmitters
    POJ 1474 Video Surveillance
    seajs 的研究一 无题
  • 原文地址:https://www.cnblogs.com/ckxkexing/p/9135013.html
Copyright © 2011-2022 走看看