Codeforces Round #465 (Div. 2) C. Fifa and Fafa(计算几何)

链接
给你一个圆和一个点,让你在给定圆内画一个圆,使得答案圆不能包含给定点,而且使得给定圆没有被答案圆覆盖的面积最小。输出答案圆的圆心和半径即可。
解析:分三种情况考虑:
当点在圆外时:
那么给出的圆就符合条件,直接输出圆心和坐标即可
当给出的点和圆心重合时:
此时的坐标为(x1+r/2,y1),半径为r/2
当给出的点在圆内时:
这里写图片描述

这是半径好求,圆心就要用相似三角形来求了,比赛时一直想求直线与园的交点,也是比较困难的

#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
const int N=1e7+100;
double dis(double x1,double y1,double x2,double y2)
{
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
int main()
{
    double r,x1,x2,y1,y2;
    cin>>r>>x1>>y1>>x2>>y2;
    double len=dis(x1,y1,x2,y2);
    if(len>=r*r)
        cout<<x1<<' '<<y1<<' '<<r<<endl;
    else if(x1==x2&&y1==y2)
        cout<<x1+r/2<<" "<<y1<<' '<<r/2<<endl;
    else
    {
        double Z=sqrt(len);
        double R=(Z+r)/2;
        cout<<(x1-x2)*R/Z+x2<<' '<<(y1-y2)*R/Z+y2<<' '<<R<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ffgcc/article/details/80037371
今日推荐