ICPCCamp2017 Day 4 A The Catcher in the Rye(二分+光的折射定律)
来源:互联网 发布:正在准备windows请不要 编辑:程序博客网 时间:2024/05/07 01:59
大体题意:
告诉你有三个矩形连在一起,要求你从第一个矩形左下角出发,到第三个矩形的右上角,在每个矩形中速度不一样,求最少时间?
思路:
最容易想到的是三分。
取第一个矩形的走的高度是x, 第二个玻璃走的高度是y,列一个函数发现是一个凹函数。
三分就好了。但是时间是0.25s 过不了。
不过有大神 有一个小技巧,就是把这三个矩形 缩小h倍。 最后算完 在乘回去。 (好猛= =)
其实正解是二分。
把它想成光线, 肯定有一个唯一确定的光线路径。
利用光的折射定律来二分。
只需要二分枚举第一个路径的角度, 就可以算出剩下的两个来,加起来看是否是高度H即可。
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#define sqr(x) ((x)*(x))using namespace std;const double eps = 1e-10;const double pi = acos(-1.0);int T;double h,a,b,c,va,vb,vc;int mm = 16;double oo = 1e5+10;inline int dcmp(double a,double b){ if (fabs(a-b) < eps) return 0; if (a < b) return -1; return 1;}double ha,hb,hc;void go(double m){ double sina = sin(m); double cosa = sqrt(1-sqr(sina)); double tana = sina/cosa; ha = tana*a; double sinb = sina*vb/va; double cosb = sqrt(1-sqr(sinb)); double tanb = sinb/cosb; hb = b*tanb; double sinc = sina*vc/va; double cosc = sqrt(1-sqr(sinc)); double tanc = sinc/cosc; hc = c*tanc;}int main(){ scanf("%d",&T); while(T--){ scanf("%lf %lf %lf %lf %lf %lf %lf",&h, &a, &b, &c, &va, &vb, &vc); double l = 0, r = pi/2; while(r-l > eps){ double m = (l+r)/2; go(m); if (dcmp(ha+hb+hc,h) < 0) l=m; else r = m; } go((l+r)/2); printf("%.10f\n",sqrt(sqr(ha)+sqr(a))/va + sqrt(sqr(hb)+sqr(b))/vb + sqrt(sqr(hc)+sqr(c))/vc); } return 0;}/**210 3 4 3 1 1 121 5 12 4 4 3 4**/
0 0
- ICPCCamp2017 Day 4 A The Catcher in the Rye(二分+光的折射定律)
- A Day in the Life of IT
- Day in the Life of a Googler
- ICPCCamp2017 Day 4 F Factory(三分套三分)
- KernelBugFixing - A day in the life of a fixed bug
- 动态规划(4)Testing the CATCHER 1887
- ICPCCamp2017 Day 5 I Coprime Queries(莫比乌斯函数 + 容斥定理 + 二分)
- 极限编程立方体 —— XP程序员的一天(XP Programmer's Cube - A Day in the Life)
- POJ 1887 Testing the CATCHER(LIS)
- POJ_1887_Testing the CATCHER
- Testing the CATCHER
- DP_poj1887_Testing the CATCHER
- Testing the CATCHER (P1887)
- UVa231 - Testing the CATCHER
- POJ1887--Testing the CATCHER
- poj1887 Testing the CATCHER
- POJ1887 Testing the CATCHER
- Testing the CATCHER
- 深度学习基础之 - 行人检测SSD
- Linux基本操作
- AOE网关键路径之白话解析
- 关于Mysql数据库的优化
- jdm分布式架构框架
- ICPCCamp2017 Day 4 A The Catcher in the Rye(二分+光的折射定律)
- 虚拟主机应该如何设置
- linux vim配置详解
- Thymeleaf的算术操作和比较操作
- 链表
- CodeForces - 744A (并查集)
- Android项目之ImageLoader_获取磁盘缓存
- java基础系列之生产者消费者模式
- Struts2验证框架的命名