博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5144 NPY and shot(物理运动学+三分查找)
阅读量:6155 次
发布时间:2019-06-21

本文共 2059 字,大约阅读时间需要 6 分钟。

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 
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 }

 

转载于:https://www.cnblogs.com/ECJTUACM-873284962/p/6557130.html

你可能感兴趣的文章
[20170628]12C ORA-54032.txt
查看>>
Linux磁盘管理和文件系统管理
查看>>
linux运维人员的成功面试总结案例分享
查看>>
Windows DHCP Server基于MAC地址过滤客户端请求实现IP地址的分配
查看>>
命令查询每个文件文件数
查看>>
《跟阿铭学Linux》第8章 文档的压缩与打包:课后习题与答案
查看>>
RAC表决磁盘管理和维护
查看>>
Apache通过mod_php5支持PHP
查看>>
发布一个TCP 吞吐性能测试小工具
查看>>
java学习:jdbc连接示例
查看>>
PHP执行批量mysql语句
查看>>
Extjs4.1.x 框架搭建 采用Application动态按需加载MVC各模块
查看>>
Silverlight 如何手动打包xap
查看>>
建筑电气暖通给排水协作流程
查看>>
JavaScript面向对象编程深入分析(2)
查看>>
linux 编码转换
查看>>
POJ-2287 Tian Ji -- The Horse Racing 贪心规则在动态规划中的应用 Or 纯贪心
查看>>
Windows8/Silverlight/WPF/WP7/HTML5周学习导读(1月7日-1月14日)
查看>>
关于C#导出 文本文件
查看>>
使用native 查询时,对特殊字符的处理。
查看>>