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 ...
随机推荐
- matlab之sub2ind()函数
将下标转换为线性索引 语法 linearInd = sub2ind(matrixSize, rowSub, colSub) 说明 linearInd = sub2ind(matrixSize, row ...
- Codeforces 366C Dima and Salad:背包dp
题目链接:http://codeforces.com/problemset/problem/366/C 题意: 有n个物品,每个物品有两个属性a[i]和b[i]. 给定k,让你选出一些物品,使得 ∑ ...
- Linux下system函数
http://www.jb51.net/article/40517.htm 浅析如何在c语言中调用Linux脚本 http://blog.csdn.net/koches/article/detai ...
- eslipse 修改tomcat server location 解决HTTP Status 404 – Not Found
Eclipse中tomcat service设置选择window ----show view---services可以看到服务的面板双击tomcat进入配置界面Service Locations(Sp ...
- 20179215《Linux内核原理与分析》第一周作业
一.Linux介绍 我们现在很常见Windows系统,对于Linux则显得尤为陌生.当然我也不例外,初识Linux过程中遇到一些困惑,但我也在实验的同时通过不断查找资料与实践中慢慢解决问题.那么下面我 ...
- ES+open-falcon之报警自动发送请求信息
当我们监控nginx的状态码出现错误状态码的时候, 一般的处理方法是通过kibana查询是哪个接口导致从而确定是哪个服务,再进一步登录业务机器查询业务日志确定原因. 我们现在要做的事情就是将 人为的通 ...
- uoj problem 14 DZY Loves Graph
题目: DZY开始有 \(n\) 个点,现在他对这 \(n\) 个点进行了 \(m\) 次操作,对于第 \(i\) 个操作(从 \(1\) 开始编号)有可能的三种情况: Add a b: 表示在 \( ...
- bzoj 4530 大融合 —— LCT维护子树信息
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4530 用LCT维护子树 size,就是实边和虚边分开维护: 看博客:https://blog ...
- Swift错误处理
相对于可选中运用值的存在与缺失来表达函数的成功与失败,错误处理可以推断失败的原因,并传播至程序的其他部分. throws关键词 一个函数可以通过在声明中添加throws关键词来抛出错误消息. func ...
- Python:删除字符串中的字符
一.删除字符串两端的一种或多种字符 #strip().lstrip().rstrip()方法:(默认删除空格符) A.list.strip(字符):删除字符串两端的一种或多种字符: #例:删除字符串s ...