【HDOJ】3400 Line belt
三分。
#include <cstdio>
#include <cstring>
#include <cmath> typedef struct {
double x, y;
} Point_t; Point_t A, B, C, D;
const double eps = 1.0e-8;
double P, Q, R; double dist(Point_t a, Point_t b) {
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} double t_ab(Point_t a, Point_t b) {
return dist(a, b)/P;
} double t_cd(Point_t c, Point_t d) {
return dist(c, d)/Q;
} double t_oth(Point_t x, Point_t y) {
return dist(x, y)/R;
} double tri_cd(Point_t c, Point_t d, Point_t S) {
Point_t left = c, right = d;
Point_t p1, p2; while (dist(left, right) > eps) {
p1.x = left.x*2.0/3.0 + right.x/3.0;
p1.y = left.y*2.0/3.0 + right.y/3.0;
p2.x = left.x/3.0 + right.x*2.0/3.0;
p2.y = left.y/3.0 + right.y*2.0/3.0;
if (t_oth(S, p1)+t_cd(p1, D) <= t_oth(S, p2)+t_cd(p2, D)) {
right = p2;
} else {
left = p1;
}
}
return t_oth(S, left) + t_cd(left, d);
} double tri_ab(Point_t a, Point_t b) {
Point_t left = a, right = b;
Point_t p1, p2; while (dist(left, right) > eps) {
p1.x = left.x*2.0/3.0 + right.x/3.0;
p1.y = left.y*2.0/3.0 + right.y/3.0;
p2.x = left.x/3.0 + right.x*2.0/3.0;
p2.y = left.y/3.0 + right.y*2.0/3.0;
if (t_ab(a, p1)+tri_cd(C, D, p1) <= t_ab(a, p2)+tri_cd(C, D, p2)) {
right = p2;
} else {
left = p1;
}
}
return t_ab(a, left) + tri_cd(C, D, left);
} 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", tri_ab(A, B));
} return ;
}
【HDOJ】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 (三分嵌套)
题目链接 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上行走的时间 ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
- 【HDOJ】4328 Cut the cake
将原问题转化为求完全由1组成的最大子矩阵.挺经典的通过dp将n^3转化为n^2. /* 4328 */ #include <iostream> #include <sstream&g ...
- 【HDOJ】3553 Just a String
后缀数组加二分可解. /* 3553 */ #include <iostream> #include <sstream> #include <string> #in ...
随机推荐
- Android源码学习
http://android-wheel.googlecode.com/svn/trunk/android-wheel-read-only 在github上面有一个叫做 android-wheel 的 ...
- [React Flow] Up and Running with Facebook Flow for Typed JavaScript
Install: npm i -D flow-binnpm i -g flow-bin Init: flow init Script: "typecheck": "flo ...
- Ubuntu常见问题
1. Ubuntu16.04安装完国际版QQ后发现用不了搜狗输入法 sudo mv /usr/bin/ibus-daemon /usr/bin/ibus-daemon.bak
- Python开发【第一篇】:目录
本系列博文包含 Python基础.前端开发.Web框架.缓存以及队列等,希望可以给正在学习编程的童鞋提供一点帮助!!! Python开发[第一篇]:目录 Python开发[第二篇]:初识Python ...
- poj 1780 code(欧拉路)
/* 对于n为密码想要序列最短 那么 1234 2345 这两个一定挨着 就是说 前一个的后n-1位是后一个的前n-1位 假设n==3 我们用0-99作为点的编号建图 然后每个点连出去10条边 两个相 ...
- 转载:C# 中的委托
原文地址 http://www.tracefact.net/CSharp-Programming/Delegates-and-Events-in-CSharp.aspx 感谢博主分享! 引言 委托和 ...
- JavaScript自动关闭窗口
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 13、SQL Server 自定义函数
SQL Server 自定义函数 在SQL Server中不仅可以使用系统函数(如:聚合函数,字符串函数,时间日期函数等)还可以根据需要自定义函数. 自定义函数分为标量值函数和表值函数. 其中,标量值 ...
- Ubuntu12.04安装insight-6.8
insight是在Linux下一个比较好用的GDB的前端 insight首页:http://sourceware.org/insight/index.php 在这里下载源码:insight-6.8.t ...
- cas sso单点登录系列4_cas-server登录页面自定义修改过程(jsp页面修改)
转:http://blog.csdn.net/ae6623/article/details/8861065 SSO单点登录系列4:cas-server登录页面自定义修改过程,全新DIY. 目标: ...