zoukankan      html  css  js  c++  java
  • HDU 5144 三分

    开始推导用公式求了好久(真的蠢),发现精度有点不够。

    其实这种凸线上求点类的应该上三分法的,当作入门吧...

    /** @Date    : 2017-09-23 21:15:57
      * @FileName: HDU 5144 三分 无聊物理题.cpp
      * @Platform: Windows
      * @Author  : Lweleth (SoungEarlf@gmail.com)
      * @Link    : https://github.com/
      * @Version : $Id$
      */
    #include <bits/stdc++.h>
    #define LL long long
    #define PII pair<int ,int>
    #define MP(x, y) make_pair((x),(y))
    #define fi first
    #define se second
    #define PB(x) push_back((x))
    #define MMG(x) memset((x), -1,sizeof(x))
    #define MMF(x) memset((x),0,sizeof(x))
    #define MMI(x) memset((x), INF, sizeof(x))
    using namespace std;
    
    const int INF = 0x3f3f3f3f;
    const int N = 1e5+20;
    const double eps = 1e-8;
    const double Pi = acos(-1.0);
    const double g = 9.80;
    
    double check(double agl, double v0, double h)
    {
    	double va = v0 * sin(agl);
    	double vb = v0 * cos(agl);
    	double c = 2 * g * h;
    	double t1 = va / g;
    	double t2 = sqrt(c + va * va) / g;
    	double x = (t1 + t2) * vb; 
    	return x;
    }
    
    
    int main()
    {
    	int T;
    	cin >> T;
    	while(T--)
    	{
    		double h, v;
    		scanf("%lf%lf", &h, &v);
    		double l = 0, r = Pi / 2.0;
    		while(r - l > eps)
    		{
    			double lmid = l + (r - l) / 3.00;
    			double rmid = r - (r - l) / 3.00;
    			if(check(lmid,v,h) > check(rmid,v,h))
    				r = rmid;
    			else l = lmid;
    		}
    		printf("%.2lf
    ", check(l,v,h));
    	}
        return 0;
    }
    
  • 相关阅读:
    C 文件随机读写
    fread(),fwrite()函数
    C 将文本文件内容逆序打印
    C++ 文件复制
    关机效果
    xpath的语法
    ajax json 数据
    转帖 ASP.NET中高级程序员 面试题
    数据库查询的执行顺序
    【转载】母版页引用外部文件的路径问题
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/7583322.html
Copyright © 2011-2022 走看看