Uva-10341-solve It (two-part solution)

Source: Internet
Author: User
Tags mathematical constants






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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.