1857: [Scoi2010]传送带
Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 1938 Solved: 1055
[Submit][Status][Discuss]
Description
在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段。两条传送带分别为线段AB和线段CD。lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R。现在lxhgww想从A点走到D点,他想知道最少需要走多长时间
Input
输入数据第一行是4个整数,表示A和B的坐标,分别为Ax,Ay,Bx,By 第二行是4个整数,表示C和D的坐标,分别为Cx,Cy,Dx,Dy 第三行是3个整数,分别是P,Q,R
Output
输出数据为一行,表示lxhgww从A点走到D点的最短时间,保留到小数点后2位
Sample Input
0 0 0 100
100 0 100 100
2 2 1
100 0 100 100
2 2 1
Sample Output
136.60
HINT
对于100%的数据,1<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000
1<=P,Q,R<=10
Source
我奶了一口斜率肯定是单调的,所以直接上了三分套三分2333
然后就A了???、
#include<bits/stdc++.h>
#define ll long long
#define D double
const D eps=1e-15;
using namespace std;
struct node{
D x,y;
node operator -(const node &u)const{
return (node){x-u.x,y-u.y};
}
node operator +(const node &u)const{
return (node){x+u.x,y+u.y};
}
node operator *(const D &u)const{
return (node){x*u,y*u};
}
}a[5];
D P,Q,R;
inline D sq(D x){
return x*x;
}
inline D dis(node x,node y){
return sqrt(sq(x.x-y.x)+sq(x.y-y.y));
}
inline D g(D tmp1,D tmp2){
node x=a[1]+a[2]*tmp1,y=a[4]+a[3]*tmp2;
return dis(a[1],x)/P+dis(a[4],y)/Q+dis(x,y)/R;
}
inline D f(D tmp1){
D l=0.00,r=1.00,ml,mr;
while(r-l>=eps){
ml=(l*2+r)/3,mr=(l+r*2)/3;
if(g(tmp1,ml)<g(tmp1,mr)) r=mr;
else l=ml;
}
return g(tmp1,l);
}
int main(){
for(int i=1;i<=4;i++) scanf("%lf%lf",&a[i].x,&a[i].y);
a[2]=a[2]-a[1],a[3]=a[3]-a[4];
scanf("%lf%lf%lf",&P,&Q,&R);
D l=0.00,r=1.00,ml,mr;
while(r-l>=eps){
ml=(l*2+r)/3,mr=(l+r*2)/3;
if(f(ml)<f(mr)) r=mr;
else l=ml;
}
printf("%.2lf
",f(l));
return 0;
}