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

题目意思:就是给你两条线段AB , CD的坐标 ,一个人在AB以速度p跑,在CD上以q跑,在其他地方跑速度是r,问你从A到D最少的时间。
解题思路:设E在AB上,F在CD上。 则人在线段AB上花的时间为:f = AE / p,人走完Z和Y所花的时间为:g= EF / r + FD / q
f函数是一个单调递增的函数,而g很明显是一个先递减后递增的函数。两个函数叠加,所得的函数应该也是一个先递减后递增的函数。这算是一道三分又三分的题目,可以看成是三分的镶嵌,
先对AB上的位置E进行三分枚举,每一次枚举的时候把E看做定点,在这种情况下,再对CD上的位置F进行三分枚举,这样可以求出此次三分AB的最小时间。然后完成对AB的三分后,就会得到从A到D的最短时间。
 #include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
#define EPS 1e-8
struct Point
{
double x;
double y;
} a, b, c, d, e, f;
double p, q, r;
double dis(Point p1, Point p2)///两点之间的距离
{
return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
double calc(double alpha)///alpha代表在f点在cd中位置的比率
{
f.x = c.x + (d.x - c.x) * alpha;
f.y = c.y + (d.y - c.y) * alpha;
return dis(f, d) / q + dis(e, f) / r;///返回在ef和fd上花费的时间
}
double inter_tri(double alpha)///在f点进行三分
{
double l = 0.0, r = 1.0, mid, mmid, cost;
e.x = a.x + (b.x - a.x) * alpha;
e.y = a.y + (b.y - a.y) * alpha;///e点在线段ab中的位置
while (r - l > EPS)
{
mid = (l + r) / ;
mmid = (mid + r) / ;
cost = calc(mid);
if (cost <= calc(mmid))
r = mmid;
else
l = mid;
}
return dis(a, e) / p + cost;
}
double solve()///在e点进行三分
{
double l = 0.0, r = 1.0, mid, mmid, ret;
while (r - l > EPS)
{
mid = (l + r) / ;
mmid = (mid + r) / ;
ret = inter_tri(mid);
if (ret <= inter_tri(mmid))
r = mmid;
else
l = mid;
}
return ret;
}
int main()
{
int T;
double ans;
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);
ans=solve();
printf("%.2lf\n",ans);
}
return ;
}

 

Line belt(三分镶嵌)的更多相关文章

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

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

  2. HDU 3400 Line belt (三分嵌套)

    题目链接 Line belt Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

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

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

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

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

  5. Line belt

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

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

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

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

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

  8. hdu Line belt

    这道题是一道3分搜索的题.其实这种题很多时候都出现在高中的解析几何上,思路很简单,从图中可以看到,肯定在AB线段和CD线段上各存在一点x和y使得所花时间最少 因为AB和CD上的时间与x和y点的坐标都存 ...

  9. hdu 3400 Line belt 三分法

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

随机推荐

  1. 使用 jTessBoxEditor 生成 tesseract-orc 的字典

    本文使用图片方式记录使用 jTessBoxEditor 一站式生成自动文件的方式 首先感谢 Tesseract OCR 讨论群 389402579 的管理员[创世倾城 QQ:457606663] 的帮 ...

  2. JsonCpp在vs中使用

    Jsoncpp是c++生成和解析Json数据的跨平台开源库.下面简介如何在vs中使用. 1.官网下载.https://sourceforge.net/projects/jsoncpp/解压文件得到js ...

  3. 课时133.margintop失效原因(理解)

    我们之前讲过如果只有子元素设置了margin top而父元素没有边框则会跟着被顶下来的. 而我们怎么解决这个问题呢? 就是给父元素设置一个边框 而为什么我们在第二个浮动的盒子设置边框没有用呢?应为第一 ...

  4. php源码建博客2--实现单入口MVC结构

    主要: MVC目录结构 数据库工具类制作 创建公共模型类和公共控制器类 --------------文件结构:-------------------------------------- blog├─ ...

  5. Java常用容器对比

    ArrayList与Vector ArrayList和Vector内部都是由数组实现的,数组实现的优点就是支持元素的随机访问(O(1)),但是在对元素进行插入和删除操作时,需要向后或向前移动数组,这样 ...

  6. 昊合数据整合平台HHDI常见问题

    Q: HaoheDI和Informatica PowerCenter.IBM DataStage的区别在哪里? A: Informatica和DataStage是比较重量级的ETL平台,其自身就是比较 ...

  7. Linux重启命令介绍

    下面介绍在 Linux 操作系统中重启和关闭相关的命令:shutdown.reboot.init.halt.poweroff.systemctl,你可以根据需要来选择适合的 Linux 命令关闭或重新 ...

  8. java instanceof 的理解

    简单来说,java 中的instanceof 运算符是用来在运行时指出对象是否是特定类的一个实例.instanceof通过返回一个布尔值来指出,这个对象是否是这个特定类或者是它的子类的一个实例. 用法 ...

  9. Developing iOS 8 Apps with Swift (stanford)

    https://www.youtube.com/watch?v=JkiB8Zwk-9Q&index=2&list=PLcX0opNQliFl0RTGbY9HHWCFg0Q8_fIF4

  10. Tomcat7 调优及 JVM 参数优化

      Tomcat 的缺省配置是不能稳定长期运行的,也就是不适合生产环境,它会死机,让你不断重新启动,甚至在午夜时分唤醒你.对于操作系统优化来说,是尽可能的增大可使用的内存容量.提高CPU 的频率,保证 ...