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
题意:鲍勃射箭(注意实在平面射箭,刚开始我也理解错了,但是后来看到没有高度所以,不可能在空间),鲍勃在(0,0),给出苹果的坐标,和箭飞的速度,求最小角度;
解题思路:现在0-pi之间用三分求出最大角度,要是最大角度都飞不到苹果的地方就不可能射到就输出-1,否则,再在0-在大角度之间求最小角度;
感悟:二分这里没什么解题思路可以写,无非就是控制精度的,懂了题意就用二分或三分解;
代码(g++)
#include

#include

#include

#define g 9.8

#define pi
3.1415926535897932384626433832795028841971693993751058209

//这次就不听pi精度还不够

double x,y,v;

double  distance_y(double s)

{

    return
v*sin(s)*x/(v*cos(s))-4.9*x*x/(v*cos(s)*v*cos(s));

}

int main()

{

   
//freopen("in.txt", "r", stdin);

    double
mid1,mid2,first,endn,sum1,sum2;

    int n;

   
scanf("%d",&n);

    for(int
i=0;i

    {

       
scanf("%lf%lf%lf",&x,&y,&v);

       
first=0;

       
endn=pi;//再大就反向Q了;

       
while(fabs(endn-first)>1e-8)//三分来判断最大的那个角度

  {

   mid1=first+(endn-first)/3;

mid2=endn-(endn-first)/3;

sum1=distance_y(mid1);

sum2=distance_y(mid2);

if(sum1>sum2)

endn=mid2;

else

    first=mid1;

}

  if(distance_y(first)

  {

   printf("-1\n");

continue;

}

  first=0;

  while(fabs(endn-first)>1e-8)//二分找最小值

{

   mid1=(endn+first)/2;

sum1=distance_y(mid1);

if(sum1

    first=mid1;

else

    endn=mid1;

}

  printf("%.6lf\n",endn);

    }

}

Toxophily的更多相关文章

  1. HDU2298 Toxophily

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...

  2. HDU 2298 Toxophily

    题目: Description The recreation center of WHU ACM Team has indoor billiards, Ping Pang, chess and bri ...

  3. HDU 2298 Toxophily(公式/三分+二分)

    Toxophily Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. HDU 2298 Toxophily 【二分+三分】

    一个人站在(0,0)处射箭,箭的速度为v,问是否能够射到(x,y)处,并求最小角度. 首先需要判断在满足X=x的情况下最大高度hmax是否能够达到y,根据物理公式可得 h=vy*t-0.5*g*t*t ...

  5. HDU -2298 Toxophily(三分法)

    这道题目,可以推出物理公式直接来做,但是如果推不出来就必须用程序的一种算法来实现了,物理公式只是适合这一个或者某个题,但是这种下面这种解决问题的方法确实解决了一类问题 ----三分法,大家可能都听说过 ...

  6. HDU-2298 Toxophily (三分法入门系列)

    题意: 意大利炮射出炮弹的速度为v,求在(0,0)击中(x,y)处的目标,发射炮弹的角度. 题解: 设f(α)表示角度为α时, f(α) = vsin(α) * t - 4.9 * t * t   ① ...

  7. 【三分+精度问题】G. Toxophily

    https://www.bnuoj.com/v3/contest_show.php?cid=9154#problem/G [题意] 已知人的坐标在(0,0),靶的位置在(x,y),人以速度v射箭并且射 ...

  8. HDU 2298:Toxophily(推公式)

    http://acm.hdu.edu.cn/showproblem.php?pid=2298 题意:给出一个x,y,v,问从(0,0)以v为初速度射箭,能否射到(x,y)这个点,如果能,输出最小的射出 ...

  9. Toxophily HDU - 2298 三分+二分

    代码+解析: 1 //题意: 2 //有一个大炮在(0,0)位置,为你可不可以把炮弹射到(x,y)这个位置 3 //题目给你炮弹初始速度,让你求能不能找出来一个炮弹射出时角度满足题意 4 //题解: ...

随机推荐

  1. getOutputStream() has already been called for this response

    错误日志里偶尔会有getOutputStream() has already been called for this response这个错误 最近发现了高概率复现条件,所以顺手解决了一下: 首先根 ...

  2. HTML5基本标签的使用

    第一次写这种东西,肯定存在许多不足之处,还望大家多多担待,我会继续加油的!我也是一名HTML5的初学者,只是将这几周在课堂上所听到的东西分享给大家. 下面给大家介绍一下H5! 一.<!DOCTY ...

  3. 简易RPC框架-私有协议栈

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  4. 3.bootstrap-组件

    1.图标 <button type="button" class="btn btn-default"> <span class="g ...

  5. windows7下MongoDB(V3.4)的使用及仓储设计

    简单的介绍一下,我使用MongoDB的场景. 我们现在的物联网环境下,有部分数据,采样频率为2000条记录/分钟,这样下来一天24*60*2000=2880000约等于300万条数据,以后必然还会增加 ...

  6. 代码与编程(java基础)

    代码与编程(面试与笔试java) 1.写一个Singleton出来 Singleton模式主要作用是保证在Java应用程序中,一个类Class只有一个实例存在. 一般Singleton模式通常有几种种 ...

  7. S2_OOP第三章

    第一章 多态 概念 多态是具有表现多种型生态的能力的特征,同一个实现接口,使用不同的实例而执行不同的操作 子类转换父类(向上转型) 用父类接受子类,向上转型 向上转型的规则: 讲一个父类的引用志向一个 ...

  8. PyCharm基本操作

    1.1 PyCharm基本使用 视频学习连接地址:http://edu.51cto.com/course/9043.html 1.1.1 在Pycharm下为你的Python项目配置Python解释器 ...

  9. OC中成员属性 成员变量

    比如用property声明一个变量属性 然后我们会为它用懒加载的方式重写get方法 然后我们在使用这个变量的时候,都是用self.itemArray,为什么这样用比较好呢,这是因为self.是对属性的 ...

  10. Vue实现选项卡切换

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...