HDU 2298 三分
阿新 • • 發佈:2017-09-24
拋物線 can 給定 mem -- for () make pair
斜拋從(0,0)到(x,y),問其角度。
首先觀察下就知道拋物線上橫坐標為x的點與給定的點的距離與角度關系並不是線性的,當角度大於一定值時可能會時距離單調遞減,所以先三分求個角度範圍,保證其點一定在拋物線下方,這樣距離和角度的關系就是單調的了,再二分角度即可。
/** @Date : 2017-09-23 23:17:11 * @FileName: HDU 2298 三分.cpp * @Platform: Windows * @Author : Lweleth ([email protected]) * @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.8; double check(double agl, double x, double v) { if(x == 0 && agl - Pi / 2.00 < eps) return v * v / 2.000 / g; double va = v * sin(agl); double vb = v * cos(agl); double t = x / vb; double y = va * t - g * t * t / 2; return y; } int main() { int T; cin >> T; while(T--) { double x, y, v; scanf("%lf%lf%lf", &x, &y, &v); if(x == 0) { double ny = check(Pi/2.00, 0, v); if(y - ny > eps) printf("-1\n"); else printf("%.6lf\n", Pi/2.00); continue; } double l = 0; double r = Pi / 2.0; while(r - l > eps) { double lmid = (l + l + r) / 3.0; double rmid = (l + r + r) / 3.0; if(check(lmid, x, v) > check(rmid, x, v))//三分一個最大角度範圍使點總在曲線下方 r = rmid; else l = lmid; } if(y - check(l, x, v) > eps) { printf("-1\n"); continue; } double ll = 0; double rr = l; while(rr - ll > eps) { double mid = (ll + rr) / 2.0; if(check(mid, x, v) - y > eps) rr = mid; else ll = mid; } printf("%.6lf\n", ll); } return 0; }
HDU 2298 三分