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. eclipse官方下载地址

    下载地址:  https://www.eclipse.org/downloads/packages/release/Luna/SR2 选择不同版本

  2. .Net Core如何在任意位置获取配置文件的内容

    前几天群里有人问,我想在程序里的任意位置读取appsetting.json里的配置,该怎么搞. 话不多说上源码 首先,要想读取配置文件我们要用到IConfiguration 接口,这个接口在Start ...

  3. thinkphp 5.1/tp5.1 route路由bug

    tp5.1下面RuleItem类中,match方法. 如果同一个控制器下面,写了两个路由,后一个路由比包含前一个路由,则访问后一个路由地址的时候,会跳转到前面定义的那个路由

  4. 6、core dump 故障分析

    Core Dump-定义Core Dump又叫核心转存.当程序在运行过程中发生异常, 这时Linux系统可以把程序出错时的内存内容存储在一个core文件中, 这种过程叫Core Dump. Segme ...

  5. IPV6路由技术

    OSPFV3 一.OSPFv3概述:协议号89 1.概念: OSPFv3是ospf(开放式最短路径优先)版本3的简称,主要提供对IPV6的支持,遵循的标准为RFC2740(OSPF for IPv6) ...

  6. BAPC 2014 Preliminary

    // 题目链接: https://nanti.jisuanke.com/t/282041 //动态规划,重复利用子问题的最优,来求解当前最优问题 #include <iostream> # ...

  7. 20145202马超《网络对抗》Exp8 Web基础

    1.本实践的具体要求有: (1).Web前端HTML(1分) 能正常安装.启停Apache.理解HTML,理解表单,理解GET与POST方法,编写一个含有表单的HTML. (2).Web前端javas ...

  8. CF 600 E. Lomsat gelral

    E. Lomsat gelral http://codeforces.com/contest/600/problem/E 题意: 求每个子树内出现次数最多的颜色(如果最多的颜色出现次数相同,将颜色编号 ...

  9. MySQL高级-MySQL安装

    1.mysql安装 检查系统是否安装过mysql 查询命令:rpm -qa|grep -i mysql 删除命令:rpm -e RPM软件包名(该名字是上一个命令查出来的名字) 安装命令:rpm -i ...

  10. HTML5项目笔记10:使用HTML5 IndexDB设计离线数据库

    之前的文章(http://www.cnblogs.com/wzh2010/archive/2012/05/22/2514017.html)里面描述了HTML5 离线数据存储的Web SQL,一个基于S ...