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. OpenStack Pike超详细搭建文档 LinuxBridge版

    前言 搭建前必须看我 本文档搭建的是分布式P版openstack(1 controller + N compute + 1 cinder)的文档. openstack版本为Pike. 搭建的时候,请严 ...

  2. Java的垃圾回收

    Java的垃圾回收 System.gc()和Runtime.gc()用来请求JVM启动垃圾回收 try与return的问题 任何调用try 或者catch中的return语句之前,都会先执行final ...

  3. 防止html5的video标签在iphone中自动全屏

    问题: 当在iphone中打开html5页面中的video视频时,会默认调取系统播放器,全屏播放视频资源. 解决方式: 1. 首先在html5页面的video标签中添加webkit-playsinli ...

  4. xcode7.3 iTunes Store operation failed解决

    使用apploader上传程序 提示:如果您安装了XCode开发环境.在/Applications/XCode.app/Contents/Applications目录中可以找到Application ...

  5. Visual Studio + Qt开发环境搭建

    1. 安装Visual Studio 2015 Visual Studio 2015下载地址如下,安装比较常规,不做介绍. Visual Studio Enterprise 2015 with Upd ...

  6. CentOS6.x服务器OpenSSH平滑7.3p版本——拒绝服务器漏洞攻击

    对于新安装的Linux服务器,默认OpenSSH及OpenSSL都不是最新的,需要进行升级以拒绝服务器漏洞攻击.本次介绍的是升级生产环境下CentOS6.x系列服务器平滑升级OpenSSL及OpenS ...

  7. 洗礼灵魂,修炼python(4)--从简单案列中揭示常用内置函数以及数据类型

    上一篇说到print语句,print是可以打印任何类型到屏幕上,都有哪些类型呢? 整形(int) 长整型(long) 浮点型(float) 字符型(str) 布尔型(bool) 最常见的就这几种. 在 ...

  8. 移植Linux-3.4.2内核到S3C2440

    一.BootLoader引导内核过程     1.Bootloader的工作     1.1.将内核读入内存     2.2.保存内核启动参数到指定位置,内核启动时去这个位置解析参数     3.3. ...

  9. python --- hashlib模块使用详解

    这个模块实现了一个通用的接口来实现多个不同的安全哈希和消息摘要算法.包括FIPS安全散列算法SHA1,SHA224,SHA256,SHA384和SHA512(在FIPS 180-2中定义)以及RSA的 ...

  10. 【NOIP】OpenJudge - 15-03:雇佣兵

    #include<stdio.h>//雇佣兵 int main() { ; scanf("%d%d%d",&M,&N,&X); n=N; m=M ...