hoj2298Toxophily【二分+三分】

来源:互联网 发布:淘宝pc端首页焦点图 编辑:程序博客网 时间:2024/06/04 17:48



Toxophily

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1511    Accepted Submission(s): 790


Problem Description
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
30.222018 23.901887 121.90918339.096669 110.210922 20.270030138.355025 2028.716904 25.079551
 

Sample Output
1.561582-1-1

题意:给定水果的坐标一个人站在(0,0)的位置射该苹果问仰角多大

解题思路:因为射出后的足迹为抛物线只需判断该点是否在该抛物线上即可因为要射中则该点必须在上升过程;由此利用三分法确定仰角的范围;之后再二分确定角度

#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#define eps 1e-8#define G 9.8 #include<algorithm>#define PI 3.1415926535897932using namespace std;double x,y,v;int sgn(double n){if(fabs(n))return 0;else if(n<0)return 1;return 1;}double gety(double angle){double t=x/(v*cos(angle));return v*sin(angle)*t-0.5*G*t*t;}void Bina(double angle){double left=0,right=angle;int size=100;while(size--){double mid=(left+right)/2.0;if(gety(mid)>y)right=mid;elseleft=mid;}printf("%.6lf\n",left);}void Three(){double mid,mmid;double left=0,right=PI/2.0;double h1,h2;int size=100;while(size--){mid=(left+right)/2.0;mmid=(mid+right)/2.0;h1=gety(mid);h2=gety(mmid);if(h1>h2)right=mmid;else left=mid;}double cnt=gety(left);if(cnt<y)printf("-1\n");else Bina(left);}int main(){int t,i,j,k;scanf("%d",&t);while(t--){scanf("%lf%lf%lf",&x,&y,&v);Three();}return 0;}


0 0
原创粉丝点击