hoj2298Toxophily【二分+三分】
2015-09-24 10:51
246 查看
ToxophilyTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1511 Accepted Submission(s): 790 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 |
解题思路:因为射出后的足迹为抛物线只需判断该点是否在该抛物线上即可因为要射中则该点必须在上升过程;由此利用三分法确定仰角的范围;之后再二分确定角度
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #define eps 1e-8 #define G 9.8 #include<algorithm> #define PI 3.1415926535897932 using namespace std; double x,y,v; int sgn(double n){ if(fabs(n))return 0; else if(n<0)return 1; return 1; } double gety(double angle){ double t=x/(v*cos(angle)); return v*sin(angle)*t-0.5*G*t*t; } void Bina(double angle){ double left=0,right=angle; int size=100; while(size--){ double mid=(left+right)/2.0; if(gety(mid)>y) right=mid; else left=mid; } printf("%.6lf\n",left); } void Three(){ double mid,mmid; double left=0,right=PI/2.0; double h1,h2; int size=100; while(size--){ mid=(left+right)/2.0; mmid=(mid+right)/2.0; h1=gety(mid); h2=gety(mmid); if(h1>h2)right=mmid; else left=mid; } double cnt=gety(left); if(cnt<y) printf("-1\n"); else Bina(left); } int main() { int t,i,j,k; scanf("%d",&t); while(t--){ scanf("%lf%lf%lf",&x,&y,&v); Three(); } return 0; }
相关文章推荐
- shell脚本报错 /bin/bash^M: bad interpreter
- 在Tomcat 6下运行正常,但是在Tomcat 7下异常。
- 使用docker-compose快速安装redmine
- [转]NMON服务器监控、指标说明
- ES7之Decorators实现AOP示例
- 【疯狂labview】 Xcontrol+LVoop封装练习 Toolbar
- linux基础整理2
- Linux命令行快捷键
- Linux命令行快捷键
- meta标签让搜索引擎搜索到你的网站
- Linux系统下安装mosh来远程连接另一台Linux主机
- unbuntu虚拟机下hadoop实例wordcount的运行
- 技术博客与网站地址
- nginx双向认证客户端配置
- hadoop MapReduce实例解析
- linux环境变量/etc/profile文件修改错误
- Struts2配置 ClassNotFoundException: rg.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilt
- Zabbix WMI 监控
- C程序员学bash shell容易掉坑的注意点(未完待续)
- shell tee