BestCoder Round #22 03 NPY and shot(三分)

NPY and shot

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 541    Accepted Submission(s): 211


Problem Description
NPY is going to have a PE test.One of the test subjects is throwing the shot.The height of NPY is H meters.He can throw the shot at the speed of v0 m/s and at the height of exactly H meters.He wonders if he throws the shot at the best angle,how far can he throw ?(The acceleration of gravity, g, is 9.8m/s2 )
 

Input
The first line contains a integer T(T10000) ,which indicates the number of test cases.
The next T lines,each contains 2 integers H(0h10000m) ,which means the height of NPY,and v0(0v010000m/s) , which means the initial velocity.
 

Output
For each query,print a real number X that was rounded to 2 digits after decimal point in a separate line.X indicates the farthest distance he can throw.
 

Sample Input
  
  
2 0 1 1 2
 

Sample Output
  
  
0.10 0.99
Hint
If the height of NPY is 0,and he throws the shot at the 45° angle, he can throw farthest.
 


题意:

扔铅球


题目描述

一个人身高为h m,他能使铅球以v0 m/s的固定初速度(在高h处)飞出去,问他应以怎样的最佳角度扔,让球飞最远。重力加速度g9.8m/s^2

输入格式

第一行一个数TT<=10000),表示数据组数,接下来T行,每行两个h0<=h<10000,v0(0<=v0<10000),表示每一组询问。

输出格式

每行一个实数,表示该组询问对应的能扔的最远距离x m,保留2位小数,四舍五入。


思路:首先用h,v,p(抛出角度),g来表示抛出距离x。x=v*v*sin(p)*cos(p)/g+v*cos(p)*sqrt((2*h/g)+v*v*sin(p)*sin(p)/g/g);

明显是单峰三分角度求出答案,角度范围为0到π/2,精度为1e-7。

拓展:精度s的确定方法,vmax=1e+4,hmax=1e+4,sinx斜率最大为1,则认为sin(x2)-sin(x1)=x2-x1=s。因为f(x2)的误差不能超过0.001,所以s*1e+4<=1e-3,所以s<=1e-7.


AC代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#include<math.h>
using namespace std;
#define PI9 asin(1.0)
double h,v,g=9.8;
double f(double p){
return v*v*sin(p)*cos(p)/g+v*cos(p)*sqrt((2*h/g)+v*v*sin(p)*sin(p)/g/g);
}

int main(){
    double l,r;
    int t;
    cin>>t;
    while(t--){
        cin>>h>>v;
        l=0,r=PI9;
        while(r-l>1e-7){
            double mid1=(r+l)/2;
            double mid2=(mid1+r)/2;
            if(f(mid1)<f(mid2)) l=mid1;
            else r=mid2;
        }
        printf("%.2lf\n",f(r));
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值