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. JS(三)

    上周介绍了JS中两个比较重要的东西,循环和函数,这周再给大家介绍一下BOM和DOM 一.BOM 1.首先来说一下什么是BOM,BOM即浏览器对象模型,说白一点就是与浏览器进行的交互的对象模型. 2.B ...

  2. org.springframework.core.io包内的源码分析

    前些日子看<深入理解javaweb开发>时,看到第一章java的io流,发觉自己对io流真的不是很熟悉.然后看了下JDK1.7中io包的一点点代码,又看了org.springframewo ...

  3. hdu 5937 -- Equation(搜索)

    题目链接 problem description Little Ruins is a studious boy, recently he learned addition operation! He ...

  4. JSP静态化(伪静态)

    关于URLRewirte的用法:该方法只是实现了url的伪静态化,并不是真正的静态化. URLRewirte版本:urlrewrite-2.6.0.jar URLRewirte的用处: 1.满足搜索引 ...

  5. Python GUI - Tkinter tkMessageBox

    Python GUI - Tkinter tkMessageBox: tkMessageBox模块用于显示在您的应用程序的消息框.此模块提供了一个功能,您可以用它来显示适当的消息     tkMess ...

  6. zoj3710 friends(floyd变形)

    Friends Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice lives in the country where people li ...

  7. 用$.getJSON() 和$.post()获取第三方数据做页面 ——惠品折页面(1)

    用$.getJSON() 和$.post()获取第三方数据做页面 首页 index.html 页面 需要jquery  和 template-web  js文件   可以直接在官网下载 中间导航条的固 ...

  8. IDL 指针

    IDL指针与C.C++和FORTRAN等其他程序语言的指针不同,它所处的多变量是可以动态分配内存的全局变量,不只想真正的内存地址 1.创建和访问指针 指针用指针函数Ptr_New()来创建,通过“*” ...

  9. python爬虫之获取验证码登陆

    #--coding:utf-8#author:wuhao##这里我演示的就是本人所在学校的教务系统#import urllib.requestimport urllib.parseimport rei ...

  10. Django Cookie 和 Sessions 应用

    在Django里面,使用Cookie和Session看起来好像是一样的,使用的方式都是request.COOKIES[XXX]和request.session[XXX],其中XXX是您想要取得的东西的 ...