题目链接

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. Oracle可能会遇到问题和解决方法

    1.plsql developer查询一列用中文,出现乱码 添加环境变量NLS_LANG = SIMPLIFIED CHINESE_CHINA.ZHS16GBK->软件重启 2.ORA-1251 ...

  2. cmd(或者说DOS窗口)输出内容到文件

    格式是:command >> filefullpath 格式是:DOS命令>>文件名全路径 举例说明: dir *.* >> D:\abc.txt dir *.* ...

  3. 提醒程序员注意的一些事项--R

    经验丰富的程序员通常会发现R语言的某些方面不太寻常.以下是这门语言中你需要了解的一些特性. 对象名称中的句点(.)没有特殊意义.但美元符号($)却有着和其他语言中的句点类似的含义,即指定一个对象中的 ...

  4. WCF之契约的分类(部分為參考他人)

    什么是契约呢?在使用WCF时,对其制定各种各样的规则,就叫做WCF契约.任何一个分布式的应用程序在传递消息的时候都需要实现制定一个规则. 任何一个分布式应用程序,它之所以能够互相传递消息,都是事先制定 ...

  5. windows 10 安装 spark 环境(spark 2.2.1 + hadoop2.7)

    安装步骤基本参考 Spark在Windows下的环境搭建.不过在安装新版本 spark2.2.1(基于 hadoop2.7)的配置时,略略有一些不同. 1. sqlContext => spar ...

  6. PS色调— —通道混合

    clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); Image=im ...

  7. u盘安装ubuntu 12.04 server问题解决

    问题: 使用UltraISO 9.5.3制作U盘启动盘,ISO文件使用ubuntu-12.04.2-server-i386.iso,ISO文件经过MD5验证是正确的. 将U盘查到计算机上,进bios选 ...

  8. windows 7下mingw+msys编译ffmpeg

      windows 7下mingw+msys编译ffmpeg   1-->下载安装MingW,mingw-get-inst-20120426.exe  http://sourceforge.ne ...

  9. 表达式(exp)

    题目大意 给定一个逻辑表达式,求每一个数满足$\in[1,n]$的使的表达式为真的方案数. 题解 题目限制较奇怪且数据范围较小,所以可以考虑直接暴力. 考虑枚举每一个变量一共出现了$k$种数值,再枚举 ...

  10. ACM学习历程—HDU 5512 Pagodas(数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5512 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是给了初始的集合{a, b},然后取集合里 ...