Toxophily HDU
来源:互联网 发布:java 创建数组 编辑:程序博客网 时间:2024/05/16 23:55
The recreation center of WHU ACM Team has indoor billiards, Ping Pang, chess and bridge, toxophily, deluxe ballrooms KTV rooms, fishing, climbing, and so on.
We all like toxophily.
Bob is hooked on toxophily recently. Assume that Bob is at point (0,0) and he wants to shoot the fruits on a nearby tree. He can adjust the angle to fix the trajectory. Unfortunately, he always fails at that. Can you help him?
Now given the object’s coordinates, please calculate the angle between the arrow and x-axis at Bob’s point. Assume that g=9.8N/m.
Input
The input consists of several test cases. The first line of input consists of an integer T, indicating the number of test cases. Each test case is on a separated line, and it consists three floating point numbers: x, y, v. x and y indicate the coordinate of the fruit. v is the arrow’s exit speed.
Technical Specification
1. T ≤ 100.
2. 0 ≤ x, y, v ≤ 10000.
Output
For each test case, output the smallest answer rounded to six fractional digits on a separated line.
Output “-1”, if there’s no possible answer.
Please use radian as unit.
Sample Input
3
0.222018 23.901887 121.909183
39.096669 110.210922 20.270030
138.355025 2028.716904 25.079551
Sample Output
1.561582
-1
-1
发射炮弹,计算抛物线能否击中某个坐标,如果能则输出最小角度。
直接三分得出的角度无法保证是最小的,而且如果判断条件是坐标是否相符也无法解决不可能击中的情况,所以要先三分找射击高度最高的情况下的角度,如果大于y坐标,则再从0到r二分找能击中的角度。
#include <stdio.h>#include <math.h>double x,y,v,sy,vx,vy,ty,tx,t;using namespace std;const double PI=acos(-1.0);bool check(double r){ vx=v*cos(r); vy=v*sin(r); tx=x/vx; sy=vy*tx-0.5*9.8*tx*tx; return (sy>y);}double ym(double r){ vx=v*cos(r); vy=v*sin(r); tx=x/vx; sy=vy*tx-0.5*9.8*tx*tx; return sy;}int main(){ int T; double low,high,mid,mmid,cm,cmm; scanf("%d",&T); while(T--){ scanf("%lf%lf%lf",&x,&y,&v); low=0;high=PI/2; while(high-low>1e-10){ mid=(low+high)/2; mmid=(mid+high)/2; cm=ym(mid); cmm=ym(mmid); // printf("%.6f %.6f %.6f %.6f\n",mid,cm,mmid,cmm); if(cm<cmm){ low=mid; }else{ high=mmid; } } if(cm<y){ printf("-1\n"); }else{ low=0,high=mid; while(high-low>1e-10){ mid=(low+high)/2; if(check(mid)){ high=mid; }else{ low=mid; } } printf("%.6lf\n",high); } } return 0;}
- Toxophily HDU
- HDU 2298 Toxophily
- hdu 2298 Toxophily
- HDU 2298 Toxophily
- HDU 2298 Toxophily
- hdu 2298 Toxophily (物理题)
- HDU 2298 Toxophily
- hdu 2298 - Toxophily [二分]
- HDU 2298 Toxophily
- HDU 1004 Toxophily
- HDU 2298 Toxophily
- day5 HDU 2298 Toxophily
- HDU 2298 Toxophily
- HDU 2298 Toxophily(水~)
- HDU 2298 Toxophily(公式推导)
- Toxophily
- Toxophily
- Toxophily
- Spark Streaming Accumulator 并发问题
- 每日linux-bg,fg,jobs,&
- 数据结构与算法分析(Java语言描述)(3)—— 冒泡排序
- iOS 应用程序生命周期
- HTML学习03-图片显示
- Toxophily HDU
- static关键字
- 第二章 SQL命令参考-LOCK
- C/C++中的const和const指针的基本用法
- ubuntu 16.04 下pip install 使用豆瓣源加速
- 融云集成-IM即时通讯
- SlidingPaneLayout点击事件穿透
- [空白] 大丈夫!
- c语言入门:指针的使用