HDU 5144 NPY and shot(物理运动学+三分查找)

简介: NPY and shot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1035    Accepted Submission(s):...

NPY and shot

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1035    Accepted Submission(s): 428

 
Problem Description
NPY is going to have a PE test.One of the test subjects is throwing the shot.The height of NPY is H meters.He can throw the shot at the speed of v0 m/s and at the height of exactly H meters.He wonders if he throws the shot at the best angle,how far can he throw ?(The acceleration of gravity, g, is  9.8m/s2)
 

Input
The first line contains a integer  T(T10000),which indicates the number of test cases.
The next T lines,each contains 2 integers H(0h10000m),which means the height of NPY,and v0(0v010000m/s), which means the initial velocity.
 

Output
For each query,print a real number X that was rounded to 2 digits after decimal point in a separate line.X indicates the farthest distance he can throw.
 

Sample Input
2
0 1
1 2

Sample Output
0.10
0.99
Hint
If the height of NPY is 0,and he throws the shot at the 45° angle, he can throw farthest.
 
Source
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5144
分析:做三分做上瘾了,再来一道,物理数学得学好啊,不然有些题就算算法知道你也写不来啊,都是思维题,典型的质点运动学+三分查找!
下面给出AC代码:
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const double pi=acos(-1.0);
 4 const double g=9.8;
 5 double v,h;
 6 const double eps=1e-8;
 7 double ans(double a)
 8 {
 9     double a1=v*v*sin(a)*sin(a);
10     double a2=2*g*h;
11     a1=a1+a2;
12     a1=sqrt(a1);
13     a1=a1/g;
14     a1=a1+v*sin(a)/g;
15     a1=a1*v*cos(a);
16     return a1;
17 }
18 int main()
19 {
20     int T;
21     while(scanf("%d",&T)!=EOF)
22     {
23         while(T--)
24         {
25           scanf("%lf%lf",&h,&v);
26           double l=0;
27           double r=pi/2;
28           double midx,midy;
29           while (r-l>eps)
30           {
31             midx=(l+l+r)/3;
32             midy=(l+r+r)/3;
33             if(ans(midx)>ans(midy))
34                 r=midy;
35             else l=midx;
36           }
37           printf("%.2f\n",ans(l));
38         }
39     }
40     return 0;
41 }

 

目录
相关文章
|
机器学习/深度学习 传感器 算法
数字图像处理实验(五)|图像复原{逆滤波和伪逆滤波、维纳滤波deconvwnr、大气湍流扰动模型、运动模糊处理fspecial}(附matlab实验代码和截图)
数字图像处理实验(五)|图像复原{逆滤波和伪逆滤波、维纳滤波deconvwnr、大气湍流扰动模型、运动模糊处理fspecial}(附matlab实验代码和截图)
735 0
数字图像处理实验(五)|图像复原{逆滤波和伪逆滤波、维纳滤波deconvwnr、大气湍流扰动模型、运动模糊处理fspecial}(附matlab实验代码和截图)
|
5月前
MATLAB中的马尔可夫区制转移(Markov regime switching)模型
MATLAB中的马尔可夫区制转移(Markov regime switching)模型
|
12月前
|
人工智能
跟着 Nature Communication 学作图 | 热图+格子注释(通路富集相关)
跟着 Nature Communication 学作图 | 热图+格子注释(通路富集相关)
189 0
|
计算机视觉
【MCTV】通过非凸总变异最小化重建凸 MR 脑图像(Matlab代码实现)
【MCTV】通过非凸总变异最小化重建凸 MR 脑图像(Matlab代码实现)
|
机器学习/深度学习
复现 sci 顶刊中的 3D 密度函数图
复现 sci 顶刊中的 3D 密度函数图
67 0
|
编解码 计算机视觉 网络架构
CVPR2021 | 重新思考BiSeNet让语义分割模型速度起飞(文末获取论文)(一)
CVPR2021 | 重新思考BiSeNet让语义分割模型速度起飞(文末获取论文)(一)
318 0
|
数据可视化 计算机视觉
CVPR2021 | 重新思考BiSeNet让语义分割模型速度起飞(文末获取论文)(二)
CVPR2021 | 重新思考BiSeNet让语义分割模型速度起飞(文末获取论文)(二)
118 0
|
机器学习/深度学习 编解码 算法
CVPR2020丨DRN:用于单图像超分辨率的对偶回归网络
论文针对这两个主要的问题进行改进,提出了对偶回归策略,通过引入对 LR 图像额外的约束,从而减小解空间的大小。也就是说,模型除了学习LR到HR图像的映射外,还学习了额外的对偶回归映射,用于估计下采样内核并重建LR图像,从而形成一个闭环以提供额外的监督。
CVPR2020丨DRN:用于单图像超分辨率的对偶回归网络
|
新零售 算法 搜索推荐
理解图表示学习中的负采样 | KDD论文解读
本文“Understanding Negative Sampling in Graph Representation Learning”已被KDD 2020录用。
理解图表示学习中的负采样 | KDD论文解读
|
机器学习/深度学习 算法 Docker
千字好文,基于未采样GraphSage算子和DGL实现的图上 Edge 回归
千字好文,基于未采样GraphSage算子和DGL实现的图上 Edge 回归