三分套三分,因为是单峰的。。。
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const double eps=1e-4;
struct pt
{
double x,y;
}a,b,c,d;
double p,q,R;
double dis(pt a,pt b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
double cal(pt m)
{
pt l=c,r=d;
while(abs(l.x-r.x)>eps||abs(l.y-r.y)>eps)
{
pt n1=(pt){(2*l.x+r.x)/3,(2*l.y+r.y)/3},n2=(pt){(l.x+2*r.x)/3,(l.y+2*r.y)/3};
if(dis(m,n1)/R+dis(n1,d)/q<dis(m,n2)/R+dis(n2,d)/q) r=n2;else l=n1;
}
return dis(m,l)/R+dis(l,d)/q;
}
int main()
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y,&p,&q,&R);
pt l=a,r=b;
while(abs(l.x-r.x)>eps||abs(l.y-r.y)>eps)
{
pt m1=(pt){(2*l.x+r.x)/3,(2*l.y+r.y)/3},m2=(pt){(l.x+2*r.x)/3,(l.y+2*r.y)/3};
if(dis(a,m1)/p+cal(m1)<dis(a,m2)/p+cal(m2)) r=m2;else l=m1;
}
printf("%.2lf",dis(a,l)/p+cal(l));
return 0;
}