HDU 3400 (三分)
2015-11-16 20:53
471 查看
题意是给你两个线段,给你线段上走的速度和线段外走的速度,然后求A到D的最小时间。
先三分第一条线段上的点,然后把这个点定下来三分求出第二个线段上的点的最小时间。
先三分第一条线段上的点,然后把这个点定下来三分求出第二个线段上的点的最小时间。
#include <bits/stdc++.h> using namespace std; #define eps 1e-8 #define pi acos (-1) struct point { double x, y; point (double _x = 0, double _y = 0) : x(_x), y(_y) {} point operator - (point a) const { return point (x-a.x, y-a.y); } point operator + (point a) const { return point (x+a.x, y+a.y); } }; point operator * (point a, double p) { return point (a.x*p, a.y*p); } point pa, pb, pc, pd; double a, b, c, t1, t2; double dis (point a, point b) { double xx = a.x-b.x, yy = a.y-b.y; return sqrt (xx*xx + yy*yy); } double work (point from) { point p = pd-pc; double l = 0.0, r = 1.0, ll, rr, p1, p2; while (r-l > eps) { ll = (l*2+r)/3.0, rr = (l+2*r)/3.0; p1 = t2*(1-ll) + dis (from, pc+p*ll) / c; p2 = t2*(1-rr) + dis (from, pc+p*rr) / c; if (p1 > p2) { l = ll; } else r = rr; } return (p1+p2)/2; } double solve () { double l = 0.0, r = 1.0, ll, rr, p1, p2; point p = (pb-pa); while (r-l > eps) { ll = (l*2+r)/3.0, rr = (l+2*r)/3.0; p1 = ll*t1 + work (pa+p*ll), p2 = rr*t1 + work (pa+p*rr); if (p1 > p2) { l = ll; } else r = rr; } return (p1+p2)/2; } int main () { //freopen ("in", "r", stdin); int t; cin >> t; while (t--) { cin >> pa.x >> pa.y >> pb.x >> pb.y >> pc.x >> pc.y >> pd.x >> pd.y; cin >> a >> b >> c; point pp = pb-pa; t1 = dis (pa, pb) / a; t2 = dis (pc, pd) / b; printf ("%.2f\n", solve ()); } return 0; }
相关文章推荐
- gmock为什么只能支持虚函数(其实也不准确)
- light oj 1012 Guilty Prince(dfs )
- iOS宏定义
- 【南大软院大神养成计划:第一天】种下21天,收获不一样的自己——前端养成启程!
- lightoj1210Efficient Traffic System
- iOS图文混排
- LayoutInflater
- 【python】xml Elementtree 学习一
- 将maven项目自动部署至私有nexus maven仓库
- 设计一款给爸爸妈妈的手机
- 顶点法线和面法线
- Objective-c:内存管理
- Objective-C运行时定义的几种重要的类型
- ViewPager
- 《leetCode》:N-Queens(奇葩的测试平台,居然不能AC)
- (原创)一般矩阵 Matrix类
- HDU 5524:Subtrees
- 列出各个部门中薪水最高的员工
- hdu 1023+1030+1134 卡特兰数+大数模板处理
- android菜鸟修炼记