HDU 2298 Toxophily(公式/三分+二分)
来源:互联网 发布:b1ued同志交友软件 编辑:程序博客网 时间:2024/05/21 17:25
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.
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.
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.
Output "-1", if there's no possible answer.
Please use radian as unit.
Sample Input
30.222018 23.901887 121.90918339.096669 110.210922 20.270030138.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|1using 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|1using 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;}
1 0
- hdu 2298 Toxophily 公式 或者 三分+二分。
- HDU 2298 Toxophily(公式/三分+二分)
- HDU 2298 Toxophily(三分+二分)
- HDU 2298 Toxophily 二分 推公式
- hdu 2298 - Toxophily [二分]
- hdu2298 Toxophily 三分+二分
- Toxophily(hdu2298三分+二分)
- HDU 2298 Toxophily(公式推导)
- Toxophily-数论以及二分三分
- HDU2298:Toxophily(三分 + 二分)
- hdoj 2298 Toxophily(数学推导或三分+二分)
- hdu 2298 二分+三分
- 【hdu2298】Toxophily——三分+二分
- HDU 2298 Toxophily
- hdu 2298 Toxophily
- HDU 2298 Toxophily
- HDU 2298 Toxophily
- hdu 2298 Toxophily (物理题)
- 浅析为什么 char 类型的范围是 : -128~+127
- [Leetcode 154, Hard] Find Minimum in Rotated Sorted Array II
- best fit line
- 重写= 覆盖 = override
- 字符串重组,字符串的插入,替换,删除,拼接
- HDU 2298 Toxophily(公式/三分+二分)
- 关于PCAP包的一点小结
- ARC机制之__weak,__autorelease详解
- 步步为营(六)贪心(5)最小区间覆盖问题
- java学习路线
- 链表A + B
- Cordys HLJ项目前端常用语法
- Swift开发必备技巧:static和class的使用
- 简单、优美的Dialog