Title: Uva10341-solve It
The idea of solving a given equation: because the equation is monotonically decreasing within the given X range. So you can try the value of x with a binary lookup. Here X is required to retain 4 decimals, so when the interval narrows to a certain range, this is the solution of X. The absence of a solution can only occur at both ends of the X range today.
Code:
#include <stdio.h> #include <stdlib.h> #include <math.h>double p, Q, R, S, T, u;const double EPS = 1e-8;do Uble f (double m) {return p * exp (-m) + Q * Sin (m) + R * cos (m) + S * TAN (m) + t * m * m + U;} Double cal () {Double L = 0;double r = 1;double m;double sum;while (R-l > EPs) {m = L + (r-l)/2;if (f (m) < 0) R = M;elsel = m;} return m;} int main () {while (scanf ("%lf%lf%lf%lf%lf%lf", &p, &q, &r, &s, &t, &u)! = EOF) {if (f (0) < 0 || F (1) > 0) printf ("No solution\n"); elseprintf ("%.4lf\n", Cal ());} return 0;}
Uva10341-solve it (two-point lookup)