注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

告别迷茫

梦想与现实的差距,就是我们生活的意义。因为我们有差距,我们才会一直积累,在努力。

 
 
 

日志

 
 

HDU 2298 Toxophily  

2014-04-26 22:59:58|  分类: 搜索的入门 二分 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

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

 


Source


 

x=v*cosα*t;

y=v*sinα*t-1/2*g*t^2;

化简消去t得 :y=x*tanα-x^2*g/(2*v^2*cosα*cosα).

三分+二分

可知该方程先递增后递减,所以先三分求出最大值,如果y小于最大值,则输出-1,否则二分求出α值。

 


首先这题是一道物理题,需要我们根据题意抽象一个函数出来。对物体的运动作分解后,可以得到:

f(t)=x*tan(t)-g*x*x/(v*cos(t))^2/2,其中t表示v与x轴正向的夹角(弧度),f(t)表示物体的运动轨迹与直线x0=x的交点纵坐标。

分析后可以得到该函数在区间(0,π/2)上先增后减,所以我们可以在该区间上三分,求出使函数取得极大值的角度t0。若f(t0)<y,则无解;否则对区间(0,t0)二分,找到使得f(t)=y的t值,即为所求。


#include<stdio.h>
#include<cmath>
double x,y,v;
const double g=9.8;

double f(double a)
{
return x*tan(a)-x*x*g/(2*v*v*cos(a)*cos(a));
}

double sanf(double bottom,double top)
{
double rightthir,leftthir;
while(top-bottom>1e-9)
{
rightthir=(bottom+top*2)/3;
leftthir=(bottom*2+top)/3;
if(f(rightthir)>f(leftthir))
{
bottom=leftthir+1e-10;
}
else
{
top=rightthir-1e-10;
}
}
return (top+bottom)/2;
}
double erfen(double bottom,double top)
{
double mid;
while(top-bottom>1e-9)
{
mid=(top+bottom)/2;
if(f(mid)>y)
{
top=mid-1e-10;
}
else
{
bottom=mid+1e-10;
}
}
return (bottom+top)/2;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf",&x,&y,&v);
double max=sanf(0,3.1415926535897932384626433832795/2.0);
if(f(max)<y)
{
printf("-1\n");
}
else
{
printf("%.6lf\n",erfen(0,max));
}
}
}


  评论这张
 
阅读(11)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017