三分套三分 --- HDU 3400 Line belt
Line belt
Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=3400
Mean:
给出两条平行的线段AB, CD,然后一个人在线段AB的A点出发,走向D点,其中,人在线段AB上的速度为P, 在线段CD上的速度为Q,在其他地方的速度为R,求人从A点到D点的最短时间。
analyse:
经典的三分套三分。
首先在AB线段上三分,确定一个点,然后再在CD上三分,确定第二个点,计算出answer。也就是嵌套的三分搜索。

Time complexity: O(logn*logm)
Source code:
// Memory Time
// 1347K 0MS
// by : crazyacking
// 2015-03-31-23.22
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iostream>
#include<algorithm>
#define MAXN 1000010
#define LL long long
using namespace std;
struct point
{
double x,y;
};
point A,B,C,D;
double p,q,r;
double length(point X,point Y)
{
return sqrt((X.x-Y.x)*(X.x-Y.x)+(X.y-Y.y)*(X.y-Y.y));
}
double time(double a,double b)
{
point X,Y;
X.x=a*(B.x-A.x)+A.x;
X.y=a*(B.y-A.y)+A.y;
Y.x=b*(C.x-D.x)+D.x;
Y.y=b*(C.y-D.y)+D.y;
return length(A,X)/p+length(D,Y)/q+length(X,Y)/r;
}
double ThiDiv(double alen)
{
double l=0.0,r=1.0,lm,rm;
while(r-l>1e-)
{
lm=(l*2.0+r)/;
rm=(l+r*2.0)/;
if(time(alen,lm)>=time(alen,rm))
l=lm;
else r=rm;
}
return time(alen,lm)<time(alen,rm)?time(alen,lm):(time(alen,rm));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
// freopen("C:\\Users\\Devin\\Desktop\\cin.cpp","r",stdin);
// freopen("C:\\Users\\Devin\\Desktop\\cout.cpp","w",stdout);
int Cas;
scanf("%d",&Cas);
while(Cas--)
{
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);
double l=0.0,r=1.0,lm,rm;
while(r-l>1e-)
{
lm=(l*2.0+r)/;
rm=(l+r*2.0)/;
if(ThiDiv(lm)>=ThiDiv(rm))
l=lm;
else r=rm;
}
printf("%.2f\n",min(ThiDiv(lm),ThiDiv(rm)));
}
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 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 搜索(三分):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的上的点找到最优点,求距离 ...
- BZOJ 1857 传送带 (三分套三分)
在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R.现在lxhgww想从 ...
- 【BZOJ-1857】传送带 三分套三分
1857: [Scoi2010]传送带 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 1077 Solved: 575[Submit][Status][ ...
随机推荐
- ZookeeperNet太难用,写了个RetryHelper来进行配套使用
普通的zk用法,如下写法: zk.Exists("/aaa", true); zk.Create(...); 但是由于这些API会抛Zookeeper的Exception,比如Co ...
- 将复杂form表单序列化serialize-object.js
<form class="form-horizontal" role="form" id="myform" action=" ...
- python排序算法的实现-插入
1.算法: 设有一组关键字{ K 1 , K 2 ,…, K n }:排序开始就认为 K 1 是一个有序序列:让 K 2 插入上述表长为 1 的有序序列,使之成为一个表长为 2 的有序序列:然后让 K ...
- dapper 操作类封装
using System; using System.Collections.Generic; using System.Data; using System.Data.SQLite; using S ...
- __getattribute__()、__getattr__()、__setattr__()、__delattr__()
访问顺序: 实例的__getattribute__().Descriptor的__get__().实例的__dict__.只读Descriptor的__get__().实例的__getattr__() ...
- 用Hibernate Tools生成Hibernate Mapping映射文件
Eclipse中要集成安装Hibernate Tools组件 如果没有,请查看:Eclipse juno 中安装 JBoss Tools,集成Hibernate 一.确定环境: 1.Maven3.0. ...
- iOS开发问题之Could not instantiate class named NSLayoutConstraint
这个问题在ios6.0之前的版本中运行会出现,因为使用Xcode 4.5之后的版本新建项目默认是选中AutoLayout的,但这个特性是在iOS6.0之后的版本中才支持的. 解决办法是选中.stroy ...
- [Z]The Boost C++ Libraries
看起来是个学习boost非常不错的材料,应该是boost的官方教程之类: http://theboostcpplibraries.com/
- SSIS:控件清单
Control Flow 控制流程 Containers 容器 For Loop Container Foreach Loop Container Sequence Container Core Ta ...
- 在unity5中减少Draw Calls(SetPass Calls)[转]
在unity5中减少Draw Calls(SetPass Calls) 我一直工作于unity5支持的Standard Shader(标准着色器)上,并且做了一些关于如何有效地减少draw cal ...