此题同样可以在洛谷P2571看到。

解题过程

这题通过思考,可以看出这是一个三分套三分的题,代码比较难啃(反正我啃了很久)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<bits/stdc++.h>
using namespace std;
double ax,ay,bx,by;
double cx,cy,dx,dy;
double p,q,r;
double dian(double x,double y,double xx,double yy){
return sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));
}
double f(double x,double y)
{
double lx = cx,ly = cy,rx = dx,ry = dy;
while(fabs(rx - lx) > 1e-10 || fabs(ry - ly) > 1e-10)
{
double m1x = (2 * lx + rx) / 3,m2x = (lx + 2 * rx) / 3,m1y = (2 * ly + ry) / 3,m2y = (ly + 2 * ry) / 3;
double a1 = dian(ax,ay,x,y) / p + dian(x,y,m1x,m1y) / r + dian(m1x,m1y,dx,dy) / q;
double a2 = dian(ax,ay,x,y) / p + dian(x,y,m2x,m2y) / r + dian(m2x,m2y,dx,dy) / q;
if(a1 > a2)lx = m1x,ly = m1y;
else rx = m2x,ry = m2y;
}
return dian(ax,ay,x,y) / p + dian(x,y,lx,ly) / r + dian(lx,ly,dx,dy) / q;
}
double solve()
{
double lx = ax,ly = ay,rx = bx,ry = by;
while(fabs(rx - lx) > 1e-10 || fabs(ry - ly) > 1e-10)
{
double m1x = (2 * lx + rx) / 3,m2x = (lx + 2 * rx) / 3,m1y = (2 * ly + ry) / 3,m2y = (ly + 2 * ry) / 3;
if(f(m1x,m1y) < f(m2x,m2y))rx = m2x,ry = m2y;
else lx = m1x,ly = m1y;
}
return f(lx,ly);
}
int main()
{
cin >> ax >> ay >> bx >> by >> cx >> cy >> dx >> dy;
cin >> p >> q >> r;
printf("%.2lf",solve());
return 0;
}

本题到这就结束了,关于三分的知识请自行百度。