G - Toxophily

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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
 
第一种是通过数学公式求解,另外一种是三分一次高度所相应的倾斜角,再二分符合条件的倾斜角
公式法:

有题目能够知道:x,y,v都是已知条件

设vx=v*cos(α),vy=v*sin(α),同一时候从P(0,0)点到达目标点花了t时间,重力加速度为G=9.8.

∴x=vx*t,y=vy*t-1/2*G*t².

消掉vx,vy,t能够转换为y=v*sin(α)*x/(v*cos(α))-1/2*g*x²/(v²*cos(α)²).

∴将sin(α)/cos(α)=tan(α);

∴y=v*x*tan(α)-(1/2*g*x²/v²)*((sin(α)²+cos(α)²)/cos(α)²);

∴y=v*x*tan(α)-(1/2*g*x²/v²)*(1+tan(α)²);

∴将其进行整理能够得到:g*x²*tan(α)²-2*v²*x*tan(α)+2*v²y+g*x²=0;

∴能够得到△=b²-4*a*c;

∴令a=g*x²,b=-2*v²*x,c=2*v²y+g*x².

又∵x1=(-b+(b²-4*a*c)½)/(2*a),x2=(-b-(b²-4*a*c)½)/(2*a).

∴能够通过上述公式将tan(α)求出,然后就是通过atan((tan(α)))将α求出

接着检查α是否符合条件就能够了。
/*
Author: 2486
Memory: 1616 KB Time: 0 MS
Language: C++ Result: Accepted
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const double PI=acos(-1);
const double G=9.8;
int T;
double x,y,v;
int main() {
scanf("%d",&T);
while(T--) {
scanf("%lf%lf%lf",&x,&y,&v);
double a=G*x*x,b=-2.0*v*v*x,c=2.0*v*v*y+G*x*x;
double posi=(-b+sqrt(b*b-4.0*a*c))/2.0/a;
double ne=(-b-sqrt(b*b-4.0*a*c))/2.0/a;
posi=atan(posi),ne=atan(ne);
if(posi>=0&&posi<=PI/2.0&&ne>=0&&ne<=PI/2.0) {
printf("%.6lf\n",posi>ne? ne:posi);
} else if(ne>=0&&ne<=PI/2.0) {
printf("%.6lf\n",ne);
} else if(posi>=0&&posi<=PI/2.0) {
printf("%.6lf\n",posi);
} else printf("-1\n");
}
return 0;
}

三分二分方法

/*
Author: 2486
Memory: 1628 KB Time: 0 MS
Language: C++ Result: Accepted
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const double PI=acos(-1);
const double eps=1e-10;
int T;
double x,y,v;
double C(double m) {
double vx=v*cos(m),vy=v*sin(m);
return (vy*x)/vx-9.8*(x/vx*x/vx)/2.0;
}
bool B(double m) {
double vx=v*cos(m),vy=v*sin(m);
return (vy*x)/vx-9.8*(x/vx*x/vx)/2.0>=y;
}
int main() {
scanf("%d",&T);
while(T--) {
scanf("%lf%lf%lf",&x,&y,&v);
double lb=0,ub=PI/2.0;
///////////////求出最大高度所相应的倾斜度////////////////
while(ub-lb>eps) {
double mid=(ub+lb)/2.0;
double mmid=(ub+mid)/2.0;
if(C(mid)>C(mmid)) {
ub=mmid;
} else lb=mid;
}
if(C(ub)<y) {
printf("-1\n");
continue;
}
///////////////////////////////
lb=0;
////////////////求出无限接近目标的倾斜度///////////////
while(ub-lb>eps) {
double mid=(ub+lb)/2.0;
if(B(mid)) {
ub=mid;
} else lb=mid;
}
///////////////////////////////
printf("%.6lf\n",ub);
}
return 0;
}

最新文章

  1. 【js跨域】js实现跨域访问的几种方式
  2. PageContext
  3. java heep space错误解决办法
  4. linux安装gcc
  5. PLSQL_基础系列10_子查询WITH AS(案例)
  6. 解决VS2012新建MVC4等项目时,收到加载程序集“NuGet.VisualStudio.Interop…”的错误
  7. java 学习连接
  8. 标准I/O介绍
  9. 剑指offier第三题
  10. Linux(CentOS6.4、CentOS6.3)下安装、配置PostgreSQL9.2
  11. 解决Ubuntu不能连接xshell
  12. Phpcms V9缩略图裁剪存在黑边的解决方法
  13. mysql-5.7.17-winx64解压版本安装图解附带一些常见问题
  14. iOS-获取通讯录联系人信息
  15. noj算法 迷宫问题 回溯法
  16. mat-form-field must contain a MatFormFieldControl错误的解决方法
  17. 【工具大道】使用SSH远程登录Mac 电脑
  18. 生成pyd文件时提示“Unable to find vcvarsall.bat”的问题
  19. [LOJ 2146][BZOJ 4873][Shoi2017]寿司餐厅
  20. zabbix3.0通过yum安装笔记

热门文章

  1. ZK框架笔记2、ZK框架安装、相关类库、web及zk配置
  2. Mybatis学习记录(六)--开发中的小问题
  3. c++对象模型介绍
  4. asp.net 完善注册登录+sqlite数据库
  5. unity3d世界坐标系和本地坐标系
  6. osgi应用使用桥接的方式打成war包部署在websphere上时遇到的与cxf相关的问题
  7. 转:微软分布式云计算框架Orleans
  8. Mac Yosemite上安装macvim和YouCompleteMe
  9. Decoration1:Spring-boot基础实现
  10. TypesMethodsAndFields