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
  • 相关阅读:
    Python列表去重
    hash表长度优化证明
    DDD初学指南
    继承和实现的明显区别
    微信商户支付
    centos7+mono4+jexus5.6.2安装过程中的遇到的问题
    SVN:重命名文件之后不允许提交
    SpringMVC 自定义全局日期转换器
    解决Cannot change version of project facet Dynamic web module to 2.5
    Maven项目热部署到Tomcat容器下
  • 原文地址:https://www.cnblogs.com/ckxkexing/p/9135013.html
Copyright © 2011-2022 走看看