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. Netty4 学习笔记之一:客户端与服务端通信 demo

    前言 因为以前在项目中使用过Mina框架,感受到了该框架的强大之处.于是在业余时间也学习了一下Netty.因为Netty的主要版本是Netty3和Netty4(Netty5已经被取消了),所以我就直接 ...

  2. 走进AngularJS

      前  言 xiaoq AngularJS 通过新的属性和表达式扩展了 HTML. 使用起来非常方便. 1. AngularJS的指令与表达式 AngularJS 通过 指令 扩展了 HTML,且通 ...

  3. nodejs中http-proxy使用小结

    最近在写xmocker的工具,用于开发前期的mock数据,不可避免的用到了代理的中间件.当然,github上有关于http-proxy封装的中间件.毕竟是自己练手的项目,就自己写了个中间件,方便定制功 ...

  4. MySQL之最基本命令

    前言:以下是数据库最基础最常用的命令,特别适用初学者练习,希望通过不断练习这些命令来熟练操作.巩固基础,因为只有不断地练习才能将知识真正变成自己的东西. 快速查看以下内容: 操作 命令 创建数据库 C ...

  5. OpenVPN client端配置文件详细说明(转)

    本文将介绍如何配置OpenVPN客户端的配置文件.在Windows系统中,该配置文件一般叫做client.ovpn:在Linux/BSD系统中,该配置文件一般叫做client.conf.虽然配置文件名 ...

  6. PHP通过访客来路获取搜索关键词的方法

    <?php class keyword{ public function getKeyword($referer){ if(strpos($referer,"http://www.ba ...

  7. Web API 路由 [二] Attribute Routing

    1) 启用.在App_Start - WebApiConfig.cs下 //在Register函数添加如下代码: config.MapHttpAttributeRoutes(); 2) 使用.Cont ...

  8. IOS系统配置FFMEPG

    在FFMPEG的官网上可以找到标准的配置文档...http://ffmpeg.org/trac/ffmpeg/wiki/MacOSXCompilationGuide 在开始前确保安装了XCODE而且也 ...

  9. Coursera_程序设计与算法_计算导论与C语言基础_数组应用练习

    您也可以在我的个人博客中阅读此文章:跳转 编程题#1:求字母的个数 描述 在一个字符串中找出元音字母a,e,i,o,u出现的次数. 输入 输入一行字符串(字符串中可能有空格,请用gets(s)方法把一 ...

  10. 怎么样防止Sql注入

    (1)对于动态构造SQL查询的场合,可以使用下面的技术: 第一:替换单引号,即把所有单独出现的单引号改成两个单引号,防止攻击者修改SQL命令的含义.再来看前面的例子,“SELECT * from Us ...