HDU 3400 Line belt (三分再三分)
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 (三分再三分)的更多相关文章
- 三分套三分 --- 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)To ...
- HDU 3400 Line belt【三分套三分】
从A出发到D,必定有从AB某个点E出发,从某个点F进入CD 故有E,F两个不确定的值. 在AB上行走的时间 f = AE / p 在其他区域行走的时间 g = EF / r 在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
题意:给你两条线段AB,CD:然后给你在AB,CD上的速度P,Q,在其它部分的速度是R,然后求A到D的最短时间. 思路:用三分枚举从AB线段上离开的点,然后再用三分枚举在CD的上的点找到最优点,求距离 ...
- hdu 3400 Line belt 三分法
思路:要求最短时间从A到D,则走的路线一定是AB上的一段,CD上的一段,AB与CD之间的一段. 那么可以先三分得到AB上的一个点,在由这个点三分CD!! 代码如下: #include<iostr ...
- 【HDOJ】3400 Line belt
三分. #include <cstdio> #include <cstring> #include <cmath> typedef struct { double ...
- Line belt(三分镶嵌)
In a two-dimensional plane there are two line belts, there are two segments AB and CD, lxhgww's spee ...
随机推荐
- [codewars_python]Best travel
Instructions John and Mary want to travel between a few towns A, B, C ... Mary has on a sheet of pap ...
- js中数组增删查改unshift、push、pop、shift、slice、indexOf、concat、join
js中数组增删查改unshift.push.pop.shift.slice.indexOf.concat.join
- vector容器的实现
简单实现了构造.析构.push_back.pop_back.operator=.operator[].clear等函数 template<class T> class my_vector ...
- C语言之基本算法26—佩尔方程求解
//穷举法! /* ====================================================== 题目:求佩尔方程x*x-73*y*y=1的解. =========== ...
- HNU13303 Counting substhreengs(递推)
题目:http://acm.hnu.cn/online/? action=problem&type=show&id=13303&courseid=0 题意:给你一个字符串,由数 ...
- javascript进阶课程--第一章--函数
javascript进阶课程--第一章--函数 学习要点 了解内存管理 掌握全局函数的使用 知识点 基本类型和引用类型 基本类型值有:undefined,NUll,Boolean,Number和Str ...
- OPENCV(2) —— Basic Structures(一)
DataType A primitive OpenCV data type is one of unsigned char, bool,signed char, unsigned short, sig ...
- Aspose.Cells相应操作及下载
Aspose.Cells相应操作 1,上传 1.1 Workbook Workbook workBook = new Workbook(); 属性: 名称 值类型 说明 Colors Color[] ...
- Vue 项目搭建 与 git 连接
整理一下::::: git 方面: -----------注册------登录--------就不用写了 这里使用的是码云: 1. 进入个人中心添加项目. 2.添加完项目添加SSH公钥.(在设置里面) ...
- cp---复制文件
cp命令用来将一个或多个源文件或者目录复制到指定的目的文件或目录.它可以将单个源文件复制成一个指定文件名的具体的文件或一个已经存在的目录下.cp命令还支持同时复制多个文件,当一次复制多个文件时,目标文 ...