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. 用JS中的cookie实现商品的浏览记录

    最近在做一个购物车效果,为了实现商品的浏览记录效果可是让我百般周折,避免以后忘记特写此随笔与大家共享,希望博友们看后有所收获. 第一步:在一个公用的js文件下getCookie(“liulan”),c ...

  2. Redis中的持久化操作

       本篇博客主要来解说一下怎样Redis中的持久化操作,当然了不是一篇理论性的博客,主要还是分享一下在redis中怎样来配置持久化操作.  1.介绍  redis为了内部数据的安全考虑,会把本身的数 ...

  3. error:assign attribute must be unsafeunretained

    今天在使用协议的过程中.偶然发现这样使用 ? 1 2 3 4 5 6 7 8 9 10 @interface AppDelegate (){     id<chatdelegate>  t ...

  4. Visual Studio2008 和2010 执行程序出现的黑框马上消失解决方法

    1 在程序最后加         system("PAUSE");  要注意包括头文件#include"stdlib.h"   //system须要调用这个   ...

  5. uestc 94(区间更新)

    题意:有一个字符串全部由'('和')'组成.然后有三种操作,query a b输出区间[a,b]字符串的括号序列是否合法.reverse a b把区间[a,b]字符串里全部'('替换成')',而且把全 ...

  6. mybatis :实现mybatis分页

    上一篇文章里已经讲到了mybatis与spring MVC的集成,并且做了一个列表展示,显示出所有article 列表,但没有用到分页,在实际的项目中,分页是肯定需要的.而且是物理分页,不是内存分页. ...

  7. HDU 2435 There is a war Dinic 最小割

    题意是有n座城市,n号城市不想让1号城市可达n号,每条道路有一条毁坏的代价,1号还可以修一条不能毁坏的道路,求n号城市所需的最小代价最大是多少. 毁坏的最小代价就直接求一遍最大流,就是最小割了.而可以 ...

  8. jdbc参数传递

    1.jdbc请求设置 将查询结果第一列coupon_id,存放在couponId中; 将查询结果第二列code,存放在coupCode中 2.参数解释: couponId_#:表示查询结果中coupo ...

  9. 玲珑学院 1010 - Alarm

    1010 - Alarm Time Limit:1s Memory Limit:128MByte DESCRIPTION Given a number sequence [3,7,22,45,116, ...

  10. Java基础算法

    i++;++i; i--;--i; int a=5;int b=a++;++放在后面,表示先使用a的值,a再加1b=5,a=a+1,a=6 int c=5;int d=++c;++放在前面,表示先将c ...