First, this is a physics question. We need to abstract a function based on the question. After decomposing the motion of an object, we can obtain: f (t) = x * tan (t)-g * x/(v * cos (t) ^ 2/2, t represents the angle (radian) between v and x axis, and f (t) represents the vertical coordinate of the intersection of the Motion Track of the object and the cross point of the line x0 = x. After analysis, we can see that the function is first increased and then reduced in the range (0, π/2), so we can obtain the angle t0 of the maximum value of the function in the range (0, π/2. If f (t0) <y, there is no solution; otherwise, for the interval (0, t0), find the t value that makes f (t) = y, that is, the request. [Cpp] # include <iostream> # include <cstdio> # include <cmath> using namespace std; const double eps = 1.0e-9; const double PI = acos (-1.0 ); const double g = 9.8; double x, y, v; double f (double t) {return x * tan (t) -g * x/2/(v * cos (t);} double two_devide (double low, double up) {double m; while (up-low> = eps) {m = (up + low)/2; if (f (m) <= y) low = m; else up = m ;} return m;} double three_devide (double low, doubl E up) {double m1, m2; while (up-low> = eps) {m1 = low + (up-low)/3; m2 = up-(up-low) /3; if (f (m1) <= f (m2) low = m1; else up = m2;} return (m1 + m2)/2;} int main () {int t; double maxt; cin> t; while (t --) {cin> x> y> v; maxt = three_devide (0, PI/2 ); if (f (maxt) <y) printf ("-1 \ n"); else printf ("%. 6lf \ n ", two_devide (0, maxt);} return 0;} but there is actually a simpler method in this question, that is, using mathematical methods to directly solve the equation .. X = v * cos (θ) * t, y = v * sin (θ) * t-g * t/2, and then undergo mathematical deformation (sin (θ) ^ 2 + cos (θ) ^ 2 = 1) to obtain the equation: g * x * tan (θ) ^ 2-2 * v * x * tan (θ) + 2 * v * y + g * x = 0. Then, use the root formula to solve the quadratic equation. (Attach the code I wrote) [cpp] # include <iostream> # include <cstdio> # include <cmath> using namespace std; const double PI = acos (-1.0 ); const double g = 9.8; int main () {int t; double x, y, v; double a, B, c, d, p1, p2; cin> t; while (t --) {cin> x> y> v; a = g * x; B =-2 * v * x; c = 2 * v * y + g * x; d = B * B-4 * a * c; if (d <0) {printf ("-1 \ n"); continue;} p1 = atan (-B + sqrt (d)/a/2 ); p2 = atan (-B-sqrt (d)/a/2); if (p1 <0 | p1> PI/2) & (p2 <0 | p2> PI/2) printf ("-1 \ n"); else if (p1 <0 | p1> PI/2) printf ("%. 6lf \ n ", p2); else if (p2 <0 | p2> PI/2) printf (" %. 6lf \ n ", p1); else printf (" %. 6lf \ n ", min (p1, p2);} return 0 ;}