这道题比较玄学,我查了很多题解也没有一个能明确给出答案单峰的原因,这题应该用三分套三分,第二层的三分很好想,只是第一层没有明确的证明,第一次写三分,心累啊。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<string>
#include<iomanip>
#include<algorithm>
using namespace std;
struct Point
{
double x,y;
Point(double u=0,double v=0){ x=u;y=v; }
Point operator -(const Point &A){return Point(x-A.x,y-A.y);}
Point operator /(const double &A){return Point(x/A,y/A);}
};
const double eps=1e-12;
Point a[2],b[2],P[2];
double p,q,r;
double sqr(double x){ return x*x; }
void read(Point &A){ scanf("%lf%lf",&A.x,&A.y); }
double dist(Point A,Point B)
{
return sqrt(sqr(B.x-A.x)+sqr(B.y-A.y));
}
double getA()
{
return dist(a[0],P[0])/p+dist(P[0],P[1])/r+dist(P[1],b[1])/q;
}
double divide3(int k)
{
Point L=a[k],R=b[k],M1,M2,del;
double A1,A2;
while (dist(L,R)>eps)
{
del=(R-L)/3;
M2=R-del;M1=M2-del;
P[k]=M1; if (k) A1=divide3(1-k); else A1=getA();
P[k]=M2; if (k) A2=divide3(1-k); else A2=getA();
if (A1< A2) R=M2; else L=M1;
}
if (dist(a[k],b[k])<=eps)
{
P[k]=a[k];
if (k) return divide3(1-k);
else return getA();
}
return A1;
}
int main()
{
for (int i=0;i<2;i++)
read(a[i]),read(b[i]);
scanf("%lf%lf%lf",&p,&q,&r);
double ans=divide3(1);
printf("%.2lf\n",ans);
return 0;
}