HDOJ 5144 NPY and shot

66 篇文章 0 订阅
29 篇文章 0 订阅

题意:给出一个物体的抛出的高度和初速度,求最远落点的位置。

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5144

思路:高中物理,通过求抛出角与水平距离之间的关系,证明可得为二次函数,三分搜索求峰值。

注意点:物理公式推错,一不小心把初速度当成y轴方向上的速度分量,查了一个小时。


以下为AC代码:

Run IDSubmit TimeJudge StatusPro.IDExe.TimeExe.MemoryCode Len.LanguageAuthor
125157042014-12-16 00:32:12Accepted5144436MS1252K1884 BG++luminous11

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;

const double pi = acos(-1);
const double eps = 0.000000001;
const double g = 9.8;
double max ( double a, double b, double c )
{
    a = max ( a, b );
    a = max ( a, c );
    return a;
}

double max ( double a, double b )
{
    return a > b ? a : b;
}

double calc ( int h, int v, double angle )
{
    double vy = sin ( angle ) * v;
    double vx = cos ( angle ) * v;
    double t = ( vy + sqrt ( 2 * g * h + vy * vy ) ) / g;
    double dis = t * vx;
    return dis;
}

double solve ( int h, int v )
{
    double l, r;
    l = 0.0 / 180.0 * pi;
    r = 90.0 / 180.0 * pi;
    double ans = 0;
    while ( r - l > eps )
    {
        double first = calc ( h, v, ( 2 * l + r ) / 3 );
        double second = calc ( h, v, ( l + 2 * r ) / 3 );
        ans = max ( ans, first, second );
        if ( first > second )
        {
            r = ( l + 2 * r ) / 3;
        }
        else
        {
            l = ( 2 * l + r ) / 3;
        }
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio( false );
    int h, v;
    int ncase;
    cin >> ncase;
    while ( ncase -- )
    {
        cin >> h >> v;
        cout << fixed << setprecision(2) << solve( h, v ) << endl;
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值