Idea: give you a formula, ask 0, from the problem conditions can be seen, this function is decreasing, so as long as the two to the middle of the answer, pay attention to the accuracy problem, because to be accurate to 4 digits after the decimal point, <1e-6 incredibly still wa,<1e-9 before, so say try to make precision high
The N-order of E here can be expressed in exp (n), or by POW (m_e, N)
The following are some of the constants defined in MATH.H:
/* Definitions of useful mathematical constants
* M_E-E
* M_LOG2E-LOG2 (E)
* M_LOG10E-LOG10 (E)
* M_ln2-ln⑵
* M_ln10-ln⑽
* M_PI-PI
* M_PI_2-PI/2
* M_PI_4-PI/4
* M_1_PI-1/PI
* M_2_PI-2/PI
* M_2_SQRTPI-2/SQRT (PI)
* M_sqrt2-sqrt⑵
* M_sqrt1_2-1/sqrt⑵
AC Code:
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include < Iostream> #define LL Long longusing namespace std;double p, Q, R, S, T, u;double Fun (double x) {return p * exp (-X) + Q * Sin (x) + R * COS (x) + S * TAN (x) + t * x * x + u;} int main () {while (scanf ("%lf%lf%lf%lf%lf%lf", &p, &q, &r, &s, &t, &u)! = EOF) {Double first = 0, Final = 1;if ((first) < 0 && Fun (final) < 0) | | (First > 0 && Fun (final) > 0)) {printf ("No solution\n"); continue;} while (Final-first > 1e-9) {Double m = first + (Final-first)/2;if (Fun (M) > 0) First = M;else final = m;} printf ("%.4lf\n", first);} return 0;}
Uva-10341-solve It (two-part solution)