Toxophily

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

Total Submission(s): 1429    Accepted Submission(s): 739

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
 

已知发射点坐标为(0,0)和重力加速度g=9.8,给出目标的坐标和初速度。求可以击中目标的最小仰角。有两种思路。第一种是直接如果可以击中目标。写出公式,化成一元二次方程,把公式内的三角函数所有化成tan,推断[0。PI/2]有无解;另外一种方法就是三分+二分。首先三分仰角,求出轨迹在x处的纵坐标最大值。若纵坐标最大值小于y,则直接输出-1,三分过后[0,r]上就是单调递增的,直接二分就可以。

#include<stack>//推导公式
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma commment(linker,"/STACK: 102400000 102400000")
#define mset0(t) memset(t,0,sizeof(t))
#define lson a,b,l,mid,cur<<1
#define rson a,b,mid+1,r,cur<<1|1
using namespace std;
const double PI=3.141592653;
const double eps=1e-8;
const int MAXN=500020;
const double g=9.8;
double x,y,v,ans; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
scanf("%lf%lf%lf",&x,&y,&v);
/*if(x==0||y==0) //这个if语句主要是用来特判0 50 10000这样的数据的。但不知道为什么去掉这个也能AC
{
if(x==0&&y==0)
printf("0.000000\n");
else if(y==0)
printf("-1\n");
else
if(v*v*0.5/g>=y)
printf("%.6lf\n",PI/2);
else
printf("-1\n");
continue;
}*/
ans=3;
double a=g*x*x;
double b=-2*v*v*x;
double c=2*v*v*y+g*x*x;
double der=b*b-4*a*c;
if(der<0)
{
printf("-1\n");
continue;
}
double ans1=atan((-b-sqrt(der))/(2*a));
double ans2=atan((-b+sqrt(der))/(2*a));
if(ans1>=0&&ans1<=PI/2)
ans=min(ans,ans1);
if(ans2>=0&&ans2<=PI/2)
ans=min(ans,ans2);
printf("%.6lf\n",ans);
}
return 0;
}
#include<stack>//三分+二分代码
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma commment(linker,"/STACK: 102400000 102400000")
#define mset0(t) memset(t,0,sizeof(t))
#define lson a,b,l,mid,cur<<1
#define rson a,b,mid+1,r,cur<<1|1
using namespace std;
const double PI=3.141592653;
const double eps=1e-8;
const int MAXN=500020;
const double g=9.8;
double x,y,v,ans; double geth(double r)
{
return (v*sin(r))*(x/(v*cos(r)))-0.5*g*(x/(v*cos(r)))*(x/(v*cos(r)));
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
scanf("%lf%lf%lf",&x,&y,&v);
if(x==0&&y==0)
{
printf("0.000000\n");
continue;
}
if(y==0)
{
printf("-1\n");
continue;
}
if(x==0)
{
if(v*v*0.5/g>=y)
printf("%.6lf\n",PI/2);
else
printf("-1\n");
continue;
}
double l=0,r=PI/2;
int cnt=10000;
while(cnt--)
{
double mid=(l+r)/2;
double mmid=(mid+r)/2;
if(geth(mid)>geth(mmid))
r=mmid;
else
l=mid;
}
if(geth(r)<y)
{
printf("-1\n");
continue;
}
l=0;
r=r;
cnt=10000;
while(cnt--)
{
double mid=(l+r)/2;
if(geth(mid)>y)
r=mid;
else
l=mid;
}
printf("%.6lf\n",r); }
return 0;
}

HDU 2298 Toxophily(公式/三分+二分)的更多相关文章

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

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

  2. HDU -2298 Toxophily(三分法)

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

  3. HDU 2298 Toxophily

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

  4. HDU 2298 三分

    斜抛从(0,0)到(x,y),问其角度. 首先观察下就知道抛物线上横坐标为x的点与给定的点的距离与角度关系并不是线性的,当角度大于一定值时可能会时距离单调递减,所以先三分求个角度范围,保证其点一定在抛 ...

  5. hdu 3433 A Task Process 二分+dp

    A Task Process Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  6. HDU 3622 Bomb Game(二分+2-SAT)

    Bomb Game Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. Toxophily HDU - 2298 三分+二分

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

  8. HDU 2298:Toxophily(推公式)

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

  9. [hdu 2298] 物理推导+二分答案

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2298 #include<bits/stdc++.h> using namespace st ...

随机推荐

  1. JavaScript sort() 方法详解

    定义和用法 sort() 方法用于对数组的元素进行排序. 语法 arrayObject.sort(sortby) 参数 描述 sortby 可选.规定排序顺序.必须是函数. 返回值 对数组的引用.请注 ...

  2. java设计师初入职场,如何站稳脚跟

    本文内容一共由3部分展开 a:新人如何快速融入团队 b:如何在职场中提升自己影响力 c:如何规进行职业规划 a:如何快速融入团队   能在层层选拔下进入公司,说明你工作的能力还是得到公司的认可,不过这 ...

  3. Scrum Meeting Alpha - 7

    Scrum Meeting Alpha - 7 NewTeam 2017/11/1 地点:新主楼F座二楼 任务反馈 团队成员 完成任务 计划任务 安万贺 登录部分的API仍存在问题 完成登陆部分的AP ...

  4. 一起写框架-MVC框架-基础功能-Date类型数据绑定(七)

    实现功能 表单请求传递的数据,格式为以下格式的日期时间数据. (1):yyyy-MM-dd hh:mm:ss (2):yyyy-MM-dd 执行方法可以使用Date类型接收. 实现思路 1.获得表单字 ...

  5. [转载] 红黑树(Red Black Tree)- 对于 JDK TreeMap的实现

    转载自http://blog.csdn.net/yangjun2/article/details/6542321 介绍另一种平衡二叉树:红黑树(Red Black Tree),红黑树由Rudolf B ...

  6. java的配置环境简介

    ============================================================================== 学java对很多人来说并不陌生,听的最多的 ...

  7. tornado的非异步阻塞模式

    [优化tornado阻塞任务的三个选择] 1.优化阻塞的任务,使其执行时间更快.经常由于是一个DB的慢查询,或者复杂的上层模板导致的,这个时候首要的是加速这些任务,而不是优化复杂的webserver. ...

  8. PL/SQL 游标 (实验七)

    PL/SQL 游标 emp.dept 目标表结构及数据 要求 基于部门表建立游标dept_cursor1,使用记录变量接收游标数据,输出部门表信息: 显示格式: 部 门 号: XXX 部门名称: XX ...

  9. 【OCR技术系列之一】字符识别技术总览

    最近入坑研究OCR,看了比较多关于OCR的资料,对OCR的前世今生也有了一个比较清晰的了解.所以想写一篇关于OCR技术的综述,对OCR相关的知识点都好好总结一遍,以加深个人理解. 什么是OCR? OC ...

  10. 把项目中的那些恶心的无处存储的大块数据都丢到FastDFS之快速搭建

        在我们开发项目的时候,经常会遇到大块数据的问题(2M-100M),比如说保存报表中1w个人的ID号,他就像一个肿瘤一样,存储在服务器哪里都 觉得恶心,放在redis,mongodb中吧,一下子 ...