Uva10341-solve it (two-point lookup)

Source: Internet
Author: User

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)

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.