开始推导用公式求了好久(真的蠢),发现精度有点不够。
其实这种凸线上求点类的应该上三分法的,当作入门吧...
/** @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; }