HDU 6097 Mindis

做P点关于圆的反演点P’,OPD与ODP’相似,相似比是|OP| : r。

Q点同理。

极小化PD+QD可以转化为极小化P’D+Q’D。

当P’Q’与圆有交点时,答案为两点距离,否则最优值在中垂线上取到。

时间复杂度 O(1)

具体图形看这个博客http://blog.csdn.net/qq_34845082/article/details/77099332

以下是代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
const int N = 3e5+5;
const double eps = 1e-8;
struct node
{
    double x,y;
};
int main()
{
    int t ;
    scanf("%d",&t);
    while(t--)
    {
        double r ;
        scanf("%lf",&r);
        node a,b;
        node a1,b1;
        scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
        double dis1 = sqrt(a.x*a.x+a.y*a.y);
        if(dis1<eps)
        {
            printf("%.7f\n",2*r );
            continue ;
        }
        double kk = r*r/dis1/dis1;
        a1.x=kk*a.x;a1.y=a.y*kk;b1.x=kk*b.x;b1.y=kk*b.y;
        node mid ;
        mid.x = (a1.x + b1.x)/2 ;
        mid.y = (a1.y + b1.y)/2 ;
        double dis = sqrt(mid.x*mid.x + mid.y*mid.y);
        double ans ;
        if(dis<=r)
            ans = sqrt((a1.x-b1.x)*(a1.x-b1.x)+(a1.y-b1.y)*(a1.y-b1.y))
            ans = ans*dis1/r;
        else
        {
            double temp = r/dis;
            node ans1 ; ans1.x=temp*mid.x;ans1.y=temp*mid.y;
            ans=2*sqrt((ans1.x-a.x)*(ans1.x-a.x)+(ans1.y-a.y)*(ans1.y-a.y));
        }
        printf("%.7f\n",ans );
    }
    return 0 ;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值