题目链接

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 ;
}

最新文章

  1. iOS 摇一摇的功能
  2. 利用netperf、iperf、mtr测试网络
  3. UVA 10192 Vacation
  4. bzoj 2878: [Noi2012]迷失游乐园
  5. SD-WAN技术分析
  6. uuid-不好之处
  7. C++中的虚函数解析[The explanation for virtual function of CPlusPlus]
  8. Swift超详细的基础语法-结构体,结构体构造器,定义成员方法, 值类型, 扩充函数
  9. MVC中HtmlHelper用法大全参考
  10. windows 查看端口被哪个程序占用
  11. Android 内核常见目录的作用
  12. 浅谈css3有意思的属性pointer-events: none;
  13. 二叉查找树的C++实现
  14. ServerSocketChannel、SocketChannel、Selector等概念04
  15. WireShark Flow capture analysis
  16. 修改Egret引擎代码的方法
  17. 蓝牙协议分析(5)_BLE广播通信相关的技术分析
  18. 从零写Java Web框架——请求的处理DispatcherServlet
  19. Unity Optimization UNITY优化关注列表
  20. 更新tableView的某个cell

热门文章

  1. Eclipse快捷键与Notepad++ 快捷建冲突的问题
  2. Linux上网设置
  3. 算法(Algorithms)第4版 练习 1.5.1
  4. XShell 连接虚拟机中的服务器 失败 、连接中断(Connection closed by foreign host.)
  5. JS获取内联样式
  6. ios app被自己从应用商店下架后可以再恢復上架吗
  7. 解析XML(2)
  8. 使用命令行生成 APNG 图片
  9. Java 时间和日期类型的 Hibernate 映射
  10. Android之SurfaceView实现视频播放