Toxophily HDU - 2298 三分+二分

题目:https://vjudge.net/contest/364745#problem/B

先用三分求出最高点Y,然后在进行二分,求出角度

注意写法   PI的弧度是

acos(-1)/2-EPS接近90度的时候相当于除以0二分的精度可以用迭代次数来保证,比如100次
#include <iostream>
#include <cmath>
using namespace std;
const double EPS = 1e-8;
int T; double x, y, v;
double f(double a)//角度为a时对应的高度
{
    double t = x/(v*cos(a));
    return v*sin(a)*t - 9.8/2*t*t;
}
int main()
{
    cin >> T;
    while(T--)
    {
        cin >> x >> y >> v;
        double L = 0, R = acos(-1)/2-EPS;
        if(x==0) //特判,否则三角函数会智障掉
        {
            if(v*v/2/9.8 > y) printf("%.6lf\n", R);
            else printf("-1\n");
            continue;
        }
        for(int i=1;i<=100;i++)
        {
            double mid_L = (L+R) / 2;
            double mid_R = (mid_L+R) / 2;
            if(f(mid_L) > f(mid_R))
            {
                R = mid_R;
            } else {
                L = mid_L;
            }
        }
        if(f(L) < y) {printf("-1\n"); continue;}
        R = L, L = 0;
        for(int i=1;i<=100;i++)
        {
            double mid = (L+R)/2;
            if(f(mid) < y)
            {
                L = mid;
            } else {
                R = mid;
            }
        }
        printf("%.6lf\n", L);
    }
}

原文地址:https://www.cnblogs.com/SunChuangYu/p/12670631.html

时间: 2024-11-06 10:02:20

Toxophily HDU - 2298 三分+二分的相关文章

Hdu 1045 二分匹配

题目链接 Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6282    Accepted Submission(s): 3551 Problem Description Suppose that we have a square city with straight streets. A map of a city i

hdu 3641 数论 二分求符合条件的最小值数学杂题

http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*==================================================== 二分查找符合条件的最小值 ======================================================*/ ll solve() { __int64 low = 0, high = INF, mid ; while(low <=

HDU 4768 Flyer (二分)

OJ题目:click here~~ 题目分析:n个[a  b] 区间,对于i 属于[a  b]  ,从a开始,间隔c ,即i = a , i = a + c , i = a + 2*c -- 将x[ i ] 加1 ,x[ i ] 初值为0 . 已知最多只有一个x[ i ] 为奇数.找到这个i , 和这个奇数. 由于最多只有一个奇数,且奇数 + 偶数 = 奇数.用二分夹逼出这个奇数的位置.找到这个位置,再计算这个奇数就很容易了. AC_CODE const int maxn = 20002; LL

hdu 4400 离散化+二分+BFS(暴搜剪枝还超时的时候可以借鉴一下)

Mines Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1110    Accepted Submission(s): 280 Problem Description Terrorists put some mines in a crowded square recently. The police evacuate all peo

Codeforces 8D Two Friends 三分+二分+计算几何

题目链接:点击打开链接 题意:点击打开链接 三分house到shop的距离,二分这条斜边到cinema的距离 #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<math.h> #include<set> #include<queue> #include<vector> #include<

hdu 2962 Trucking (二分+最短路Spfa)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2962 Trucking Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1763    Accepted Submission(s): 618 Problem Description A certain local trucking co

HDU 5144 三分

开始推导用公式求了好久(真的蠢),发现精度有点不够. 其实这种凸线上求点类的应该上三分法的,当作入门吧... /** @Date : 2017-09-23 21:15:57 * @FileName: HDU 5144 三分 无聊物理题.cpp * @Platform: Windows * @Author : Lweleth ([email protected]) * @Link : https://github.com/ * @Version : $Id$ */ #include <bits/s

HDU 2295 DLX 二分

Radar Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2229    Accepted Submission(s): 888 Problem Description N cities of the Java Kingdom need to be covered by radars for being in a state of w

hdu 2298 - Toxophily [二分]

Toxophily                Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1440    Accepted Submission(s): 749 Problem Description The recreation center of WHU ACM Team has indoor billiards, Ping