分析:【三分】
三分最近距离的
(
x
x
,
y
y
)
(xx,yy)
(xx,yy)中的xx,画图可知,对于P到曲线上任一点
(
x
,
y
)
(x,y)
(x,y),并不是单峰问题。当
−
I
N
F
<
x
x
<
=
−
b
/
2
a
-INF < xx <= -b / 2a
−INF<xx<=−b/2a,对于P点到该曲线距离满足三分,同理
−
b
/
2
a
<
=
x
x
<
I
N
F
-b / 2a <= xx < INF
−b/2a<=xx<INF亦满足。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e4 + 10;
double eps = 0.000001;
double a, b, c, x, y;
double so(double xx) {
double yy = a * xx * xx + b * xx + c;
return (xx - x) * (xx - x) + (yy - y) * (yy - y);
}
int main() {
scanf("%lf %lf %lf %lf %lf", &a, &b, &c, &x, &y);
if(a == 0.0) {
printf("%.3lf\n", fabs((b * x - y + c) / sqrt(b * b + 1.0)));
return 0;
}
double L = -10000000.0, R = -b / (a + a);
while(R - L >= eps) {
double mid1 = L + (R - L) / 3;
double mid2 = R - (R - L) / 3;
if(so(mid1) >= so(mid2)) L = mid1;
else R = mid2;
}
double ans = sqrt(so(R));
L = -b / (a + a), R = 10000000.0;
while(R - L >= eps) {
double mid1 = L + (R - L) / 3;
double mid2 = R - (R - L) / 3;
if(so(mid1) >= so(mid2)) L = mid1;
else R = mid2;
}
printf("%.3lf\n", min(sqrt(so(R)), ans));
return 0;
}