题目

CF传送门

$-10^7<=x_i,y_i<=10^7,y_i!=0$
$input$

1
0 1


$output$

0.5


$input$

3
0 1
0 2
0 -3


$output$

-1


$input$

2
0 1
1 1


$output$

0.625


思路

$(X-x_i)^2+(r-y_i)^2<=r^2$

$X^2-2x_iX+{x_i}^2+r^2-2ry_i+{y_i}^2<=r^2$

$\frac{X^2-2x_iX+{x_i}^2+{y_i}^2}{2y_i}<=r$

$r=max\{\frac{(X-x_i)^2+{y_i}^2}{2y_i}\}$,我们就有确定的$r$

代码

#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
LL f=1,x=0;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
return x*f;
}
#define eps 1e-8
#define MAXN 100000
#define INF 0x3f3f3f3f
#define Mod int(1e9+7)
int n;
LL x[MAXN+5],y[MAXN+5];
double check(double X){
double r=0;//半径计算
for(int i=1;i<=n;i++)
r=max(r,((X-x[i])*(X-x[i])+y[i]*y[i])/(2.0*y[i]));
return r;
}
int main(){
int f=0;
for(int i=1;i<=n;i++){
if(y[i]<0) y[i]=-y[i],f|=1;
else f|=2;
}
if(f==3){
puts("-1");
return 0;
}
double L=-1e7-2,R=1e7+2;
while(L+eps<R){//三分横坐标
double Mid1=L+(R-L)/3,Mid2=R-(R-L)/3;
double tmp1=check(Mid1),tmp2=check(Mid2);
if(tmp1>tmp2) L=Mid1;//左边半径较大,L右移动
else R=Mid2;
}
printf("%.10lf\n",check(L));
return 0;
}