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): 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 }
复制代码

 

posted @   Angel_Kitty  阅读(312)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示
西雅图
14:14发布
西雅图
14:14发布
6°
西南风
5级
空气质量
相对湿度
93%
今天
中雨
3°/9°
周日
雨夹雪
3°/6°
周一
小雨
3°/10°