HDU 3400 Line belt (三分再三分)

ACM

题目地址: 

pid=3400" target="_blank" style="color:rgb(0,136,204); text-decoration:none">HDU 3400 Line belt

题意: 

就是给你两条线段AB , CD 。一个人在AB以速度p跑,在CD上以q跑,在其它地方跑速度是r。问你从A到D最少的时间。

分析: 

先三分AB上的点。再三分CD上的点就可以。 

证明: 

设E在AB上,F在CD上。 

令人在线段AB上花的时间为:f = AE / p,人走完Z和Y所花的时间为:g
= EF / r + FD / q

f函数是一个单调递增的函数,而g非常明显是一个先递减后递增的函数。

两个函数叠加。所得的函数应该也是一个先递减后递增的函数。故可用三分法解之。

代码:

/*
* Author: illuz <iilluzen[at]gmail.com>
* File: 3400.cpp
* Create Date: 2014-09-18 09:44:01
* Descripton: triple
*/ #include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std; #define repf(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long ll; const double EPS = 1e-8; struct Point {
double x;
double y;
} a, b, c, d, e, f; int t;
double p, q, r; double dis(Point p1, Point p2) {
return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
} double calc(double alpha) {
f.x = c.x + (d.x - c.x) * alpha;
f.y = c.y + (d.y - c.y) * alpha;
return dis(f, d) / q + dis(e, f) / r;
} double inter_tri(double alpha) {
e.x = a.x + (b.x - a.x) * alpha;
e.y = a.y + (b.y - a.y) * alpha; double l = 0.0, r = 1.0, mid, mmid, cost;
while (r - l > EPS) {
mid = (l + r) / 2;
mmid = (mid + r) / 2;
cost = calc(mid);
if (cost <= calc(mmid))
r = mmid;
else
l = mid;
}
return dis(a, e) / p + cost;
} double solve() {
double l = 0.0, r = 1.0, mid, mmid, ret;
while (r - l > EPS) {
mid = (l + r) / 2;
mmid = (mid + r) / 2;
ret = inter_tri(mid);
if (ret <= inter_tri(mmid))
r = mmid;
else
l = mid;
}
return ret;
} int main() {
ios_base::sync_with_stdio(0); cin >> t;
while (t--) {
cin >> a.x >> a.y >> b.x >> b.y;
cin >> c.x >> c.y >> d.x >> d.y;
cin >> p >> q >> r;
printf("%.2f\n", solve());
}
return 0;
}

HDU 3400 Line belt (三分再三分)的更多相关文章

  1. 三分套三分 --- HDU 3400 Line belt

    Line belt Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=3400 Mean: 给出两条平行的线段AB, CD,然后一 ...

  2. HDU 3400 Line belt (三分嵌套)

    题目链接 Line belt Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  3. HDU 3400 Line belt【三分套三分】

    从A出发到D,必定有从AB某个点E出发,从某个点F进入CD 故有E,F两个不确定的值. 在AB上行走的时间   f = AE / p 在其他区域行走的时间 g = EF / r 在CD上行走的时间   ...

  4. 搜索(三分):HDU 3400 Line belt

    Line belt Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  5. HDU 3400 Line belt (三分套三分)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=3400 题意: 有两条带子ab和cd,在ab上的速度为p,在cd上的速度为q,在其它地方的速度为r.现 ...

  6. hdu 3400 Line belt

    题意:给你两条线段AB,CD:然后给你在AB,CD上的速度P,Q,在其它部分的速度是R,然后求A到D的最短时间. 思路:用三分枚举从AB线段上离开的点,然后再用三分枚举在CD的上的点找到最优点,求距离 ...

  7. hdu 3400 Line belt 三分法

    思路:要求最短时间从A到D,则走的路线一定是AB上的一段,CD上的一段,AB与CD之间的一段. 那么可以先三分得到AB上的一个点,在由这个点三分CD!! 代码如下: #include<iostr ...

  8. 【HDOJ】3400 Line belt

    三分. #include <cstdio> #include <cstring> #include <cmath> typedef struct { double ...

  9. Line belt(三分镶嵌)

    In a two-dimensional plane there are two line belts, there are two segments AB and CD, lxhgww's spee ...

随机推荐

  1. ArcGIS api for javascript——显示地图属性

    描述 本例展示了如哦读取地图和图层的属性和返回信息给用户.本例中的四个按钮允许用户接收地图属性.每个按钮调用不同的函数. ·Get All Map Layers - 这个按钮调用getMapLayer ...

  2. 制作自己的特色PE----Mr.Zhang

    必备的文件和工具 win7.iso/win8.iso Windows系统ISO镜像 WimTool BOOT.WIM文件的改动 RegWorkShop 注冊表编辑和分析利器 UltraISO 改动wi ...

  3. centos7 ssh免口令认证登录

    摘要:centos7, xshell, 公钥,  ssh ssh登录方式有口令认证登录和密钥认证登录 接下来本次介绍是ssh密钥登录方式 (1)产生公钥 (2)将公钥放置到centos7的(/root ...

  4. BZOJ 1112 线段树

    思路: 权值线段树 (找中位数用的) 记录下出现的次数和sum 一定要注意 有可能中位数的值有许多数 这怎么办呢 (离散化以后不去重就行了嘛--.) (为什么他们想得那么麻烦) //By Sirius ...

  5. 局域网ARP病毒的清理

    局域网ARP病毒的清理 作者:IT动力源  来源:IT动力源收集整理     现在局域网中感染ARP 病毒的情况比较多,清理和防范都比较困难,给不少的网络管理员造成了很多的困扰.下面就是个人在处理这个 ...

  6. Oracle 导入导出 创建用户等

    localhost:1158/emD:\app\Administrator\product\11.2.0\dbhome_1\bin\imp.exe log  path  E:\app\Administ ...

  7. apache-maven-3.0.4-bin.zip

    http://zhidao.baidu.com/share/2a8974fd1546ef5f11ad9cccb3cabf88.html apache-maven-3.0.4-bin.zip

  8. pip版本及升级 pip安装指定模板

    昨天在微信聊天,一妹子9点的时候告诉我她要看书了,让明天聊,瞬间自己心中那颗学习的种子燃烧起来,思来想去还是继续学习自己之前未学好的python吧,因为之前有了点点的python基础,所以本次打算从p ...

  9. promise的弊端

    promise的弊端 promise彻底解决了callback hell,但也存在以下一些问题 延时问题(涉及到evnet loop)(http://www.ruanyifeng.com/blog/2 ...

  10. Spark 性能相关參数配置具体解释-任务调度篇

    作者:刘旭晖 Raymond 转载请注明出处 Email:colorant at 163.com BLOG:http://blog.csdn.net/colorant/ 随着Spark的逐渐成熟完好, ...