Time Limit: 1 SecMemory Limit: 64 MB
Submit: 2005Solved: 1091
你还在为没有学习平台而苦恼吗?你还在为没有学习资料而烦心吗?你还在为没人指导而担忧吗?可以私信小编 C++或者 加群 710520381 验证灵狐,为你提供学习的平台和资料。
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
Sample Output
136.60
HINT
对于100%的数据,1<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000
1<=P,Q,R<=10
Source
很显然最优的路线一定是从A走到AB上的一点走到CD上的一点再走到D
然后三分套三分就可以了
#include#include#include#defineeps 1e-3usingnamespace std;
inline int read() {
charc = getchar();intx =0, f =1;
while(c <'0'|| c >'9') {if(c =='-') f = -1; c = getchar();}
while(c >='0'&& c <='9') x = x *10+ c -'0',c = getchar();
returnx * f;
}int Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, P, Q, R;doubledis(doublex,doubley,doublex2,double y2) {
returnsqrt((x2 - x) * (x2 -x) + (y2 - y) * (y2 - y));
}doublecheck2(doublex,doubley,doublex2,double y2) {
returndis(Ax, Ay, x, y) / P + dis(x, y, x2, y2) / R + dis(x2, y2, Dx, Dy) / Q;
}doublecheck(doublex,double y) {
doublelx = Cx, ly = Cy, rx = Dx, ry = Dy, a, b;
while(abs(rx - lx) > eps || abs(ry - ly) > eps) {
doublewx1 = (lx *2+ rx) /3, wy1 = (ly *2+ ry) /3,
wx2 = (lx + rx *2) /3, wy2 = (ly + ry *2) /3;
a = check2(x, y, wx1, wy1);
b = check2(x, y, wx2, wy2);
if(a > b) lx = wx1, ly = wy1;
elserx = wx2, ry = wy2;
}
return check2(x, y, lx, ly);
}int main() {
#ifdef WIN32
freopen("a.in","r",stdin);
#endif Ax = read(), Ay = read(), Bx = read(), By = read(), Cx = read(), Cy = read(), Dx = read(), Dy = read(), P = read(), Q = read(), R = read();
doublelx = Ax, ly = Ay, rx = Bx, ry = By;
while(abs(rx - lx) > eps || abs(ry - ly) > eps) {
doublewx1 = (lx *2+ rx) /3, wy1 = (ly *2+ ry) /3,
wx2 = (lx + rx *2) /3, wy2 = (ly + ry *2) /3;
if(check(wx1, wy1) > check(wx2, wy2)) lx = wx1, ly = wy1;
elserx = wx2, ry = wy2;
}
printf("%.2lf", check(lx, ly));
return0;
}
网友评论