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(T≤10000),which indicates the number of test cases. The next T lines,each contains 2 integers H(0≤h≤10000m),which means the height of NPY,and v0(0≤v0≤10000m/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("%.2fn",ans(l));
38 }
39 }
40 return 0;
41 }
- 推荐一款MySQL优化工具
- HDUOJ----4502吉哥系列故事——临时工计划
- HDUOJ----4004The Frog's Games(二分+简单贪心)
- HDUOJ----4006The kth great number(最小堆...)
- HDUOJ----4501小明系列故事——买年货(三维背包)
- message 弹出窗口
- HDUOJ---1862EXCEL排序
- HDUOJ-----3591The trouble of Xiaoqian
- HDUOJ-----2571跳舞毯
- Facebook开源PyTorch版本fairseq翻译模型,训练速度提高50%
- MySQL数据清理的需求分析和改进
- Go 语言常量
- Go 语言结构
- Go 语言函数
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Django-rest-framework中过滤器的定制实例
- Python greenlet和gevent使用代码示例解析
- 完美解决pyinstaller打包报错找不到依赖pypiwin32或pywin32-ctypes的错误
- Android开发中Intent.Action各种常见的作用汇总
- Android解决ScrollView下嵌套ListView和GridView中内容显示不全的问题
- Android添加ButterKnife时报错Error:(2, 0) Cannot add extension with name 'android'的解决办法
- Python视频编辑库MoviePy的使用
- python json.dumps中文乱码问题解决
- Android定时器实现定时执行、重复执行、定时重复执行、定次数执行的多种方式
- Android开发导入项目报错Ignoring InnerClasses attribute for an anonymous inner class的解决办法
- Android中buildToolVersion与CompileSdkVersion的区别
- Glide用法与技巧以及优秀库的推荐
- Android整理好的图片压缩工具类
- Android Studio获取网络JSON数据并处理的方法
- Android使用ViewPager快速切换Fragment时卡顿的优化方案