【HDOJ】3400 Line belt

时间:2022-03-07 04:47:47

三分。

 #include <cstdio>
#include <cstring>
#include <cmath> typedef struct {
double x, y;
} Point_t; Point_t A, B, C, D;
const double eps = 1.0e-8;
double P, Q, R; double dist(Point_t a, Point_t b) {
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} double t_ab(Point_t a, Point_t b) {
return dist(a, b)/P;
} double t_cd(Point_t c, Point_t d) {
return dist(c, d)/Q;
} double t_oth(Point_t x, Point_t y) {
return dist(x, y)/R;
} double tri_cd(Point_t c, Point_t d, Point_t S) {
Point_t left = c, right = d;
Point_t p1, p2; while (dist(left, right) > eps) {
p1.x = left.x*2.0/3.0 + right.x/3.0;
p1.y = left.y*2.0/3.0 + right.y/3.0;
p2.x = left.x/3.0 + right.x*2.0/3.0;
p2.y = left.y/3.0 + right.y*2.0/3.0;
if (t_oth(S, p1)+t_cd(p1, D) <= t_oth(S, p2)+t_cd(p2, D)) {
right = p2;
} else {
left = p1;
}
}
return t_oth(S, left) + t_cd(left, d);
} double tri_ab(Point_t a, Point_t b) {
Point_t left = a, right = b;
Point_t p1, p2; while (dist(left, right) > eps) {
p1.x = left.x*2.0/3.0 + right.x/3.0;
p1.y = left.y*2.0/3.0 + right.y/3.0;
p2.x = left.x/3.0 + right.x*2.0/3.0;
p2.y = left.y/3.0 + right.y*2.0/3.0;
if (t_ab(a, p1)+tri_cd(C, D, p1) <= t_ab(a, p2)+tri_cd(C, D, p2)) {
right = p2;
} else {
left = p1;
}
}
return t_ab(a, left) + tri_cd(C, D, left);
} int main() {
int t; scanf("%d", &t);
while (t--) {
scanf("%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y);
scanf("%lf%lf%lf%lf",&C.x,&C.y,&D.x,&D.y);
scanf("%lf%lf%lf", &P, &Q, &R);
printf("%.2lf\n", tri_ab(A, B));
} return ;
}