HDU 3400 Line belt (三分嵌套)
Line belt
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2862 Accepted Submission(s): 1099
How long must he take to travel from A to D?
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
0 0 0 100
100 0 100 100
2 2 1
题意:
给出两条传送带的起点到末端的坐标,其中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 (三分嵌套)的更多相关文章
- HDU 3400 Line belt (三分再三分)
HDU 3400 Line belt (三分再三分) ACM 题目地址: pid=3400" target="_blank" style="color:rgb ...
- 三分套三分 --- HDU 3400 Line belt
Line belt Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=3400 Mean: 给出两条平行的线段AB, CD,然后一 ...
- 搜索(三分):HDU 3400 Line belt
Line belt Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 3400 Line belt (三分套三分)
http://acm.split.hdu.edu.cn/showproblem.php?pid=3400 题意: 有两条带子ab和cd,在ab上的速度为p,在cd上的速度为q,在其它地方的速度为r.现 ...
- HDU 3400 Line belt【三分套三分】
从A出发到D,必定有从AB某个点E出发,从某个点F进入CD 故有E,F两个不确定的值. 在AB上行走的时间 f = AE / p 在其他区域行走的时间 g = EF / r 在CD上行走的时间 ...
- hdu 3400 Line belt 三分法
思路:要求最短时间从A到D,则走的路线一定是AB上的一段,CD上的一段,AB与CD之间的一段. 那么可以先三分得到AB上的一个点,在由这个点三分CD!! 代码如下: #include<iostr ...
- hdu 3400 Line belt
题意:给你两条线段AB,CD:然后给你在AB,CD上的速度P,Q,在其它部分的速度是R,然后求A到D的最短时间. 思路:用三分枚举从AB线段上离开的点,然后再用三分枚举在CD的上的点找到最优点,求距离 ...
- 【HDOJ】3400 Line belt
三分. #include <cstdio> #include <cstring> #include <cmath> typedef struct { double ...
- Line belt
Problem Description In a two-dimensional plane there are two line belts, there are two segments AB a ...
随机推荐
- SpringCloud之服务提供和服务调用的搭建
pom文件: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3 ...
- 算法(Algorithms)第4版 练习 1.3.2
was best times of the was the it (1 left on stack)
- JavaWeb -- Session应用实例 -- 随机中文验证码 检验
注册页面 login.html <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html ...
- Keep DNS Nameserver Order Consistency In Neutron
一个subnet有多个dns server时,dns server在创建时就定好了,但可以update: neutron subnet-update 1a2d261b-b233-3ab9-902e-8 ...
- html5 + css3 + jQuery + 响应式布局设计
1. [代码][HTML]代码 <!DOCTYPE html><html dir="ltr" lang="zh-CN">< ...
- java:maven中webapp下的jsp不能访问web-inf下面的bean
java:maven中webapp下的jsp不能访问web-inf下面的bean 当然 WEB-INF下面的文件是不能访问的,只能吧jsp文件放入到WEB-INF下面,然后通过配置WEB-INF下we ...
- ES索引瘦身 压缩——_source _all 均disable filed store为no,引入第三方DB存储原始数据,去掉pos倒排和doc_values,强制定期merge segments,将所有fileds合并为一个field big string
原始数据:835MB ES 设置了_source _all disabled 且设置了仅仅存docs倒排Wed Feb 22 11:58:27 CST 2017Before size:1 /home/ ...
- Docker与LXC、虚拟化技术的区别——虚拟化技术本质上是在模拟硬件,Docker底层是LXC,本质都是cgroups是在直接操作硬件
先说和虚拟化技术的区别: 难道虚拟技术就做不到吗? 不不不,虚拟技术也可以做到,但是会有一定程度的性能损失,灵活度也会下降.容器技术不是模仿硬件层次,而是 在Linux内核里使用cgroup和name ...
- vscode 小笔记
用户设置: { "git.ignoreMissingGitWarning": true, "workbench.statusBar.feedback.visible&qu ...
- 重写ScrollView实现两个ScrollView的同步滚动显示
1.背景介绍 最近项目用到两个ScrollView的同步显示,即拖动左边的ScrollView滚动的同时,实现右边的ScrollView同步滚动.此种情形常用在复杂界面布局中,比如左边的ScrollV ...