本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。

本文作者:ljh2000
作者博客:http://www.cnblogs.com/ljh2000-jump/
转载请注明出处,侵权必究,保留最终解释权!

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
 
 
正解:三分
解题报告:
  居然是我写的第一道三分的题目,我好菜啊...
  根据高一物理知识,高度关于角度显然是一个单峰函数,那么我们可以通过三分来得到最高高度,如果最高高度都达不到y那么就是-1.(要用到一点高一的物理...)
  接着我们可以在我们取到最高高度的角度和0之间二分,得到最接近y的角度.
  总结起来就是一句话:二分用于有单调性的函数或者区间,三分用于单峰函数求最值
 
 
 //It is made by ljh2000
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int inf = (<<);
const double pi = acos(-);
const double eps = 1e-;
const double g = 9.80;
double X,Y,V,L,ans; inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} inline double cal(double o){
double vx,vy; vx=V*cos(o); vy=V*sin(o);
double tim=X/vx; double H=vy*tim-g*tim*tim/2.0;
return H;
} inline void three_div(){
double l=,r=pi/2.0,mm,mid;
while(r-l>eps) {
mm=l+(r-l)/; mid=mm+(r-l)/;
if(cal(mm)>cal(mid)) r=mid;
else l=mm;
}
L=l;
} inline void work(){
int T=getint(); double l,r,mid;
while(T--) {
cin>>X>>Y>>V; three_div();
if(cal(L)<Y) { printf("-1\n"); continue; }
if(fabs(cal(L)-Y)<=eps) { printf("%.6lf\n",L); continue; }
l=; r=L;
while(r-l>eps) {
mid=(l+r)*0.5;
if(cal(mid)<Y) l=mid,ans=mid;
else r=mid;
}
printf("%.6lf\n",ans);
}
} int main()
{
work();
return ;
}

HDU2298 Toxophily的更多相关文章

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

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

  2. HDU 2298 Toxophily

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

  3. Toxophily

    Problem Description The recreation center of WHU ACM Team has indoor billiards, Ping Pang, chess and ...

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

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

  5. 推公式hdu2298

    (0,0)点到(x,y)以v射箭 问 最小的角度 不能射到 -1 x=v*cos(a)*t; y=v*sin(a)*t-0.5*g*t*t; 消去t; y=x*tan(a)-0.5*g*x*x/(v* ...

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

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

  7. HDU -2298 Toxophily(三分法)

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

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

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

  9. HDU 2298:Toxophily(推公式)

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

随机推荐

  1. zabbix常用术语

    zabbix常用术语  

  2. 解决Kafka-1194问题

    生产环境中使用Kafka作为日志处理的中间件,系统结构是这样的.自12月上线一个多月来,系统运行稳定. 用过kafka的都知道,Kafka产生的消息全部存储到硬盘文件中,并且在消息被消费后不会被立即删 ...

  3. 教你如何反编译Android安装文件apk来偷窥源代码

    本文章首发于浩瀚先森博客,地址:http://www.guohao1206.com/2016/08/23/970.html 1. 准备 - java环境 安装java并配置环境 => JAVA环 ...

  4. Qt 学习笔记 TreeWidget 增删改

    在窗体上放一个TreeWidget控件和四个PushButton加一个Horizontal Spacer 布局如图 给树添加元素节点的方法和实现 .h文件 QTreeWidgetItem * AddT ...

  5. 【Flex】正则表达式

    1.基本语法 . 匹配除换行符"\n"外的任意单个字符. * 匹配前面Flex正则表达式的零次或多次出现.eg:Alert.show("ThisBookIsGoodBoo ...

  6. 【讲义提纲】以一个实战新闻cms增删改查demo为例,给学院国创队伍培训php

    PHP实战基础——以一个新闻cms的增删改查为例 一.        环境配置 二.        数据库创建 三.        增删改查demo 连接数据库 <?php $link=mysq ...

  7. Package Control Installation

    simple 用 ctrl+~ 打开 sublime 的控制台,将下面代码复制进去. sublime text2: import urllib2, os, hashlib; h = '2915d185 ...

  8. 开源磁力搜索爬虫dhtspider原理解析

    开源地址:https://github.com/callmelanmao/dhtspider. 开源的dht爬虫已经有很多了,有php版本的,python版本的和nodejs版本.经过一些测试,发现还 ...

  9. Java关键字this、super使用总结

    版权声明:原创作品,如需转载,请与作者联系.否则将追究法律责任. 作者:熔岩日期:2007-03-01MSN :leizhimin@126.com声明:原创作品,未经授权,谢绝转载! 好久没有对所学知 ...

  10. BroadcastReceiver之有序广播

    有序广播可以按一定的优先级进行传播 首先进行发送广播 public void click(View v){ Intent intent = new Intent(); intent.setAction ...