题意:
小A与小B住在同一个公寓,小B不想让小A用自己的wifi,问小B应该把wifi放在哪里
能使得小A用不到且覆盖公寓的面积最大,输出wifi位置,覆盖半径
分析:
A点到圆心O 的直线交公寓边的点B,AB的中点就是圆心 |AB|/2就是半径
我们可以用AO方向上的单位距离分别在x,y轴上表示多少来算。
bug点:
1.小A电脑可能不在公寓内
2.小A电脑如果在公寓中间需要特判否则会/0
代码:
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define LL long long
#define N 100005
#define inf 0x3f3f3f3f
#define eps 0.000001
char str[N];
double f(double x){
return x*x;
}
int main()
{
double R,x1,x2,y1,y2;
cin>>R>>x1>>y1>>x2>>y2;
if(fabs(x1-x2)<eps&&fabs(y1-y2)<eps){
double rx=(x1-R+x1)/2;
double ry=y1;
double r=R/2;
printf("%.15f %.15f %.15f\n",rx,ry,r);
return 0;
}
double d=sqrt(f(x1-x2)+f(y1-y2));
if(d>R){
printf("%.15f %.15f %.15f\n",x1,y1,R);
return 0;
}
double x=d/(x1-x2);
double y=d/(y1-y2);
double rx=R/x+x1;
double ry=R/y+y1;
rx=(x2+rx)/2;
ry=(y2+ry)/2;
double r=sqrt(f(rx-x2)+f(ry-y2));
printf("%.15f %.15f %.15f\n",rx,ry,r);
}