HDU 2298 Toxophily

来源:互联网 发布:腾讯云mysql 外网连接 编辑:程序博客网 时间:2024/05/22 03:40

Toxophily

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

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


初中物理题 刚开始以为这题是三维的….get不到题目 一直不过样例…..
令v1是平行y轴向上的分速度,v2是平行x轴向右的分速度
所以有:
y=v1*t-1/2*g*t^2; //①
x=v2*t; //②
v^2=v1^2+v2^2; //③
显然 速度v方向与x轴夹角为arctan(v1/v2)
① / ②得:
v1/v2=(y+1/2*g*t^2)/x; //④
显然 当t^2取最小值时 v1/v2有最小值 tan(x)是单调递增函数 所以arctan(v1/v2)也取得最小值
so 问题转化为求最小的t^2
联立①②③式 令k=t^2 得:
1/4*g^2*k^2-(v^2-g*y)*k+x^2+y^2=0 —>关于k的一元二次方程
dt=(v^2-g*y)^2-g^2*(x^2+y^2)>=0 k有解
且k=((v^2-g*y)+sqrt(dt))/(1/2*g^2) 或 ((v^2-g*y)-sqrt(dt))/(1/2*g^2)
当dt>0时 显然v^2-g*y>=sqrt(dt)
所以 t^2=k的最小值为((v^2-g*y)-sqrt(dt))/(1/2*g^2)
将求得的k带入④式 求arctan 就是答案


#include<iostream>#include<cstdlib>#include<cstdio>#include<string>#include<vector>#include<deque>#include<queue>#include<algorithm>#include<set>#include<map>#include<stack>#include<ctime>#include<cmath>#include<list>#include<cstring>//#include<memory.h>using namespace std;#define ll long long#define ull unsigned long long#define pii pair<int,int>#define INF 1000000007#define pll pair<ll,ll>#define pid pair<int,double>#define sci(a) scanf("%d",&a)#define scll(a) scanf("%lld",&a)#define scd(a) scanf("%lf",&a)#define scs(a) scanf("%s",a)#define pri(a) printf("%d\n",a);#define prd(a) printf("%lf\n",a);#define prd4(a) printf("%.4lf\n",a);#define prd2(a) printf("%.2lf\n",a);#define prs(a) printf("%s\n",a);const double g=9.8;int main(){    //freopen("/home/lu/文档/r.txt","r",stdin);    //freopen("/home/lu/文档/w.txt","w",stdout);    int t;    sci(t);    double x,y,v;    while(t--){        scanf("%lf%lf%lf",&x,&y,&v);        double dt=(g*y-v*v)*(g*y-v*v)-g*g*(x*x+y*y);        if(dt<0){            pri(-1);            continue;        }        double t_squ=(v*v-g*y-sqrt(dt))/(1/2.0*g*g);        double res=atan(((y+1/2.0*g*t_squ)/x));        prd(res);    }    return 0;}
0 0
原创粉丝点击