2019ACM-ICPC西安邀请赛C. Angel's Journey(计算几何)

题目链接:https://nanti.jisuanke.com/t/39270

圆参数: x y r;

点参数: x1 y1;

分两种情况:一种是x1>=x+r,此时两点距离为  直线加四分之一的圆弧

另一种就是:从点到圆上的切线距离,加’两段‘圆弧

具体看代码,画画图,挺容易的。

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define JD(x) setprecision(x)
const double PI = acos(-1.0);
const int maxn = 1e5 + 5;
 
const int mod = 1e9 + 7;
priority_queue<int, vector<int>, greater<int> >q;
int s[maxn];
signed main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
 
	int t;cin>>t;
	while(t--){
        double x,y,r,x1,y1;
        cin>>x>>y>>r>>x1>>y1;
        if(x1<x){
            x1=x+x-x1;
        }
        double h=0.25*2*PI*r;
 
        if(x1>=x+r){
            int tempx=x+r;
            printf("%.4f\n",(h+sqrt((x1-tempx)*(x1-tempx)+(y1-y)*(y1-y))));
        }
        else{
            double temp1=atan((x1-x)/(y1-y));
            double temp2=acos((r)/sqrt((x1-x)*(x1-x) + (y1-y)*(y1-y)));
            printf("%.4f\n",h+sqrt( (x1-x)*(x1-x) + (y1-y)*(y1-y)- r*r)+(PI/2.0-temp1-temp2)*r);
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值