题目链接

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没有赋值。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define LL __int64
const int maxn = 1e2 + ;
const double eps = 1e-;
using namespace std;
double p, q, r;
struct node
{
double x, y;
}a, b, c, d; double dis(node a, node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} double solve2(node t)
{
double d1, d2;
node le = c;
node ri = d;
node mid, midmid;
do
{
mid.x = (le.x+ri.x)/2.0;
mid.y = (le.y+ri.y)/2.0;
midmid.x = (mid.x+ri.x)/2.0;
midmid.y = (mid.y+ri.y)/2.0;
d1 = dis(t, mid)/r + dis(mid, d)/q;
d2 = dis(t, midmid)/r + dis(midmid, d)/q;
if(d1 > d2)
le = mid;
else ri = midmid;
}while(dis(le, ri)>=eps);
return d1;
} double solve1()
{
double d1, d2;
node le = a;
node ri = b;
node mid, midmid;
do
{
mid.x = (le.x+ri.x)/2.0;
mid.y = (le.y+ri.y)/2.0;
midmid.x = (mid.x+ri.x)/2.0;
midmid.y = (mid.y+ri.y)/2.0;
d1 = dis(a, mid)/p + solve2(mid);
d2 = dis(a, midmid)/p + solve2(midmid);
if(d1 > d2)
le = mid;
else ri = midmid;
}while(dis(le, ri)>=eps);
return d1;
} 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", solve1());
}
return ;
}

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

  1. HDU 3400 Line belt (三分再三分)

    HDU 3400 Line belt (三分再三分) ACM 题目地址:  pid=3400" target="_blank" style="color:rgb ...

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

    Line belt Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=3400 Mean: 给出两条平行的线段AB, CD,然后一 ...

  3. 搜索(三分):HDU 3400 Line belt

    Line belt Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  4. HDU 3400 Line belt (三分套三分)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=3400 题意: 有两条带子ab和cd,在ab上的速度为p,在cd上的速度为q,在其它地方的速度为r.现 ...

  5. HDU 3400 Line belt【三分套三分】

    从A出发到D,必定有从AB某个点E出发,从某个点F进入CD 故有E,F两个不确定的值. 在AB上行走的时间   f = AE / p 在其他区域行走的时间 g = EF / r 在CD上行走的时间   ...

  6. hdu 3400 Line belt 三分法

    思路:要求最短时间从A到D,则走的路线一定是AB上的一段,CD上的一段,AB与CD之间的一段. 那么可以先三分得到AB上的一个点,在由这个点三分CD!! 代码如下: #include<iostr ...

  7. hdu 3400 Line belt

    题意:给你两条线段AB,CD:然后给你在AB,CD上的速度P,Q,在其它部分的速度是R,然后求A到D的最短时间. 思路:用三分枚举从AB线段上离开的点,然后再用三分枚举在CD的上的点找到最优点,求距离 ...

  8. 【HDOJ】3400 Line belt

    三分. #include <cstdio> #include <cstring> #include <cmath> typedef struct { double ...

  9. Line belt

    Problem Description In a two-dimensional plane there are two line belts, there are two segments AB a ...

随机推荐

  1. Sobel导数

    Sobel 导数 目标 本文档尝试解答如下问题: 如何使用OpenCV函数 Sobel 对图像求导. 如何使用OpenCV函数 Scharr 更准确地计算  核的导数. 原理 Note 以下内容来自于 ...

  2. 程序以html形式发送邮件注意问题

    1.样式要写在内部,不要单独定义样式 2.div 使用背景图片在有些浏览器中出不来这时候需要用: <table style="width: 640px" cellpaddin ...

  3. runtime error 的原因

    1.  数组访问越界 2.  分母为 0 3.   括号 做题时偶然发现的! (详见 UVA 10158 War) 代码中出现了这种东西 else if( arefriends(x,y==-1)  ) ...

  4. [原创]Java开发在线编辑Word同时实现全文检索

    一.背景介绍 Word文档与日常办公密不可分,在实际应用中,当某一文档服务器中有很多Word文档,假如有成千上万个文档时,用户查找打开包含某些指定关键字的文档就变得很困难,一般情况下能想到的解决方案是 ...

  5. Python基础-random模块及随机生成11位手机号

    import random # print(random.random()) # 随机浮点数,默认取0-1,不能指定范围# print(random.randint(1, 20)) # 随机整数,顾头 ...

  6. PHP 常量、PHP 变量全解析(超全局变量、变量的8种数据类型等)

    常量特点 常量一旦被定义就无法更改或撤销定义. 常量名不需要开头的$ 与变量不同,常量贯穿整个脚本是自动全局的. 作用域不影响对常量的访问 常量值只能是字符串或数字 设置 PHP 常量 如需设置常量, ...

  7. codeforces 622D D. Optimal Number Permutation(找规律)

    D. Optimal Number Permutation time limit per test 1 second memory limit per test 256 megabytes input ...

  8. mysql 常用的存储引擎MyISAM/InnoDB比较

  9. ACM学习历程—UESTC 1215 Secrete Master Plan(矩阵旋转)(2015CCPC A)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1215 题目大意就是问一个2*2的矩阵能否通过旋转得到另一个. 代码: #include <iostre ...

  10. POJ 1664 放苹果(递归或DP)

    一.Description 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法. Input 第一行是测试数据的数目t ...