码迷,mamicode.com
首页 > 其他好文 > 详细

【Codeforces Round #465 (Div. 2) C】Fifa and Fafa

时间:2018-02-27 23:22:21      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:name   oid   .com   href   直线   logs   and   oca   out   

【链接】 我是链接,点我呀:)
【题意】


在这里输入题意

【题解】


这个x2,y2和圆心(x1,y1)相连。形成的直线和圆交于点(x3,y3)
则(x2,y2)和(x3,y3)的中点就是所求圆的圆心。
半径就是x2,y2到x3,y3的距离的一半。
写个向量的方法,求出x3,y3的坐标就好了。

【代码】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1
#define double long double
using namespace std;

const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};

LL R,x1,y1,x2,y2;

LL sqr(LL x){
    return x*x;
}

void solve(){
    cin >> R >> x1 >> y1 >> x2 >> y2;
    if (sqr(x1-x2)+sqr(y2-y1)>=sqr(R)){
        cout<<x1<<' '<<y1<<' '<<R<<endl;
        return;
    }

    if (x1==x2 && y1==y2){
        cout<<fixed<<setprecision(10)<<x1+R/2.0<<' '<<y1<<' ';cout<<fixed<<setprecision(10)<<(double)R/2.0<<endl;
        return;
    }

    double t1 = sqrt(sqr(x1-x2)+sqr(y2-y1)),t2 = R;
    double x3 = x1-t2/t1*(x2-x1);
    double y3 = y1-t2/t1*(y2-y1);
    cout<<fixed<<setprecision(10)<<(x2+x3)/2.0<<' '<<(y2+y3)/2.0<<' '<<(t1+t2)/2.0<<endl;
}

int main(){
    #ifdef LOCAL_DEFINE
        freopen("rush_in.txt", "r", stdin);
    #endif
    ios::sync_with_stdio(0),cin.tie(0);
    int T;
    T = 1;
    while(T--){
        solve();
    }
    return 0;
}

【Codeforces Round #465 (Div. 2) C】Fifa and Fafa

标签:name   oid   .com   href   直线   logs   and   oca   out   

原文地址:https://www.cnblogs.com/AWCXV/p/8481022.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!