HDU 3400 Line belt (三分嵌套)

题目链接

Line belt

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2862    Accepted Submission(s): 1099

Problem Description

In a two-dimensional plane there are two line belts, there are two segments AB and CD, lxhgww‘s speed on AB is P and on CD is Q, he can move with the speed R on other area on the plane.
How long must he take to travel from A to D?

Input

The first line is the case number T.
For each case, there are three lines.
The first line, four integers, the coordinates of A and B: Ax Ay Bx By.
The second line , four integers, the coordinates of C and D:Cx Cy Dx Dy.
The third line, three integers, P Q R.
0<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000
1<=P,Q,R<=10

Output

The minimum time to travel from A to D, round to two decimals.

Sample Input

1
0 0 0 100
100 0 100 100
2 2 1

Sample Output

136.60

Author

lxhgww&&momodi

题意:

给出两条传送带的起点到末端的坐标,其中ab为p的速度,cd为q的速度 其他地方为r的速度

求a到d点的最短时间。

分析:

首先要看出来这是一个凹型的函数,

时间最短的路径必定是至多3条直线段构成的,一条在AB上,一条在CD上,一条架在两条线段之间。

所有利用两次三分,第一个三分ab段的一点,第二个三分知道ab一点后的cd段的接点。

刚开始没用do while错了两次,因为如果给的很接近的话,上来的t1没有赋值。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <cmath>
 6 #include <algorithm>
 7 #define LL __int64
 8 const int maxn = 1e2 + 10;
 9 const double eps = 1e-8;
10 using namespace std;
11 double p, q, r;
12 struct node
13 {
14     double x, y;
15 }a, b, c, d;
16
17 double dis(node a, node b)
18 {
19     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
20 }
21
22 double solve2(node t)
23 {
24     double d1, d2;
25     node le = c;
26     node ri = d;
27     node mid, midmid;
28     do
29     {
30         mid.x = (le.x+ri.x)/2.0;
31         mid.y = (le.y+ri.y)/2.0;
32         midmid.x = (mid.x+ri.x)/2.0;
33         midmid.y = (mid.y+ri.y)/2.0;
34         d1 = dis(t, mid)/r + dis(mid, d)/q;
35         d2 = dis(t, midmid)/r + dis(midmid, d)/q;
36         if(d1 > d2)
37         le = mid;
38         else ri = midmid;
39     }while(dis(le, ri)>=eps);
40     return d1;
41 }
42
43 double solve1()
44 {
45     double d1, d2;
46     node le = a;
47     node ri = b;
48     node mid, midmid;
49     do
50     {
51         mid.x = (le.x+ri.x)/2.0;
52         mid.y = (le.y+ri.y)/2.0;
53         midmid.x = (mid.x+ri.x)/2.0;
54         midmid.y = (mid.y+ri.y)/2.0;
55         d1 = dis(a, mid)/p + solve2(mid);
56         d2 = dis(a, midmid)/p + solve2(midmid);
57         if(d1 > d2)
58         le = mid;
59         else ri = midmid;
60     }while(dis(le, ri)>=eps);
61     return d1;
62 }
63
64 int main()
65 {
66     int t;
67     scanf("%d", &t);
68     while(t--)
69     {
70         scanf("%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y);
71         scanf("%lf%lf%lf%lf", &c.x, &c.y, &d.x, &d.y);
72         scanf("%lf%lf%lf", &p, &q, &r);
73         printf("%.2lf\n", solve1());
74     }
75     return 0;
76 }
时间: 2024-08-01 10:45:47

HDU 3400 Line belt (三分嵌套)的相关文章

HDU 3400 Line belt 三分

笨蛋的难题(一) 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述        笨蛋之所以称为笨蛋,是因为他有点路痴.他一旦不高兴,就必然一个人漫无目的的出去走走.今天下雨了,他又不高兴了,怎么办?那就出去走呗,这不又丢了,这次幸好记下出来时的方向,并且在一张纸上密密麻麻的记下了他拐的弯(他很聪明吧,拐的弯都是90度的弯),0代表左拐,1代表右拐,那么多0.1,他实在看不下去了,正好遇见善良加聪明的你,你能告诉他,他现在面向哪吗? 输入 多组测试数据 第一行 输入:

HDU 3400 Line belt (三分再三分)

HDU 3400 Line belt (三分再三分) ACM 题目地址: HDU 3400 Line belt 题意: 就是给你两条线段AB , CD ,一个人在AB以速度p跑,在CD上以q跑,在其他地方跑速度是r.问你从A到D最少的时间. 分析: 先三分AB上的点,再三分CD上的点即可. 证明: 设E在AB上,F在CD上. 令人在线段AB上花的时间为:f = AE / p,人走完Z和Y所花的时间为:g = EF / r + FD / q. f函数是一个单调递增的函数,而g很明显是一个先递减后递

三分套三分 --- HDU 3400 Line belt

Line belt Problem's Link:    Mean: 给出两条平行的线段AB, CD,然后一个人在线段AB的A点出发,走向D点,其中,人在线段AB上的速度为P, 在线段CD上的速度为Q,在其他地方的速度为R,求人从A点到D点的最短时间. analyse: 经典的三分套三分. 首先在AB线段上三分,确定一个点,然后再在CD上三分,确定第二个点,计算出answer.也就是嵌套的三分搜索. Time complexity: O(logn*logm) Source code:  // M

搜索(三分):HDU 3400 Line belt

Line belt Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3531    Accepted Submission(s): 1364 Problem Description In a two-dimensional plane there are two line belts, there are two segments AB

hdu 3400 Line belt

题意:给你两条线段AB,CD:然后给你在AB,CD上的速度P,Q,在其它部分的速度是R,然后求A到D的最短时间. 思路:用三分枚举从AB线段上离开的点,然后再用三分枚举在CD的上的点找到最优点,求距离和时间就可以. 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <cmath> 5 using namespace std; 6 const double ep

【HDOJ】3400 Line belt

三分. 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 5 typedef struct { 6 double x, y; 7 } Point_t; 8 9 Point_t A, B, C, D; 10 const double eps = 1.0e-8; 11 double P, Q, R; 12 13 double dist(Point_t a, Point_t b) { 14 return

【HDU 3400】Line belt(三分法)

题目链接 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=3400 题意 有两条传送带AB和CD,移动速度分别为p,q. 除了传送带的其他区域移动速度为r,问A到D最短时间. 题目分析 在AB上找一点E,在CD上找一点F. 使得A->E->F->D时间最短. 数学思路 时间 time = |AE|/p + |EF|/r + |FD|/q. (|AE|为线段AE的长度.) 未知量有E的位置和F的位置,由于确定在AB和CD上,所以只需要两个未知量

HDU3400 Line belt (几何+三分)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3400 题意: 给定两条平行的路的左右端点的坐标.然后给定三个速度求表示在分别在两条路上的速度和不在路上走的速度 求从点A走到点D的最短时间. 分析: 先假定一个点固定的话 那么中间肯定有一个点可以使时间最小 然后是一个下凸型函数, 我们可以用三分来求.但是本题的两个点都不固定,那么思考一下 我们就可以尝试用 两个三分来做,一个三分求一条路上的点,另一个求另外一条路上的点. 注意求距离开方的时候会有

hdu Line belt

这道题是一道3分搜索的题.其实这种题很多时候都出现在高中的解析几何上,思路很简单,从图中可以看到,肯定在AB线段和CD线段上各存在一点x和y使得所花时间最少 因为AB和CD上的时间与x和y点的坐标都存在一个凸函数的关系,所以可以想到利用3分搜索的方式进行求解.当然这里要用到两个三分搜索的嵌套,锁定x后找到满足条件的y,知道最小的满足条件的x和y.用三分搜索的好处就是 可以利用两点的中点坐标公式,这样比用存数学公式求解要方便的多. #include"iostream" #include&