在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段。两条传送带分别为线段AB和线段CD。lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R。现在lxhgww想从A点走到D点,他想知道最少需要走多长时间
终于敢说我会三分了
本题是三分套三分的经典例题
分别在两个线段上三分就好了
注意精度(不要被炸成-nan)
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-4;
struct Point{
double x,y;
void read(){
cin>>x>>y;
}
};
double GetDis(Point A,Point B){
return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
struct Line{
Point A,B;
double dis;
void read(){
A.read();
B.read();
dis=GetDis(A,B);
}
Point Get_Half(double len){
if(dis-len<eps)return B;
if(len<eps)return A;
double k=len/(dis);
Point ret;
ret.x=(B.x-A.x);
ret.y=(B.y-A.y);
ret.x*=k;
ret.y*=k;
ret.x+=A.x;
ret.y+=A.y;
return ret;
}
}L1,L2;
double P,Q,R;
double f(Point A,double sum){
Point S=L2.Get_Half(sum);
return GetDis(A,S)/R+GetDis(S,L2.B)/Q;
}
double Get(double sum){
Point S=L1.Get_Half(sum);
double l=0.00;
double r=L2.dis;
while(r-l>eps){
double rr=l+(r-l)/3.0*2;
double ll=l+(r-l)/3.0;
if(f(S,rr)<f(S,ll)){
l=ll;
}
else r=rr;
}
return f(S,l)+GetDis(L1.A,S)/P;
}
int main(){
// freopen("test.in","r",stdin);
L1.read();
L2.read();
cin>>P>>Q>>R;
double l=0.00;
double r=L1.dis;
while(r-l>eps){
double rr=l+(r-l)/3.0*2;
double ll=l+(r-l)/3.0;
if(Get(rr)<Get(ll)){
l=ll;
}
else r=rr;
}
cout<<fixed<<setprecision(2)<<Get(l);
}