HDU-2199 dichotomy

Source: Internet
Author: User

Returns the root of the equation using the bipartite method.

/** Hdu-2199 can you solve the equatino * Mike-W * 2012-4-17 **/# include <stdio. h> # include <stdlib. h> # include <string. h> # include <math. h> # define EPS (1e-6) # define ndisp_x0000x2const int CO [10] = {8, 7, 2, 3, 6}; double Foo (Double X) {double X0 = Co [0]; int I; for (I = 0; I <4; I ++) X0 = x * x0 + CO [I + 1]; return x0;} double solve (Double Y) {double X1 = 0.0, X2 = 100.0, mid; double Y1 = Foo (X1), y2 = Foo (X2); While (FABS (y1-y2)> EPS) {# ifdef di Sp_xforwarx2printf ("x1, x2 = % lf, % lf \ n", x1, x2); printf ("Y1, y2 = % lf, % lf \ n", Y1, y2); # endifmid = (X1 + x2)/2; If (FOO (MID)> Y) y2 = Foo (x2 = mid ); elsey1 = Foo (x1 = mid);} return x1;} int main (void) {int t; double min_v = (double) Foo (0); double max_v = (double) foo (100); Double Y; scanf ("% d", & T); While (t --> 0) {scanf ("% lf", & Y ); if (Y> max_v | Y <min_v) printf ("no solution! \ N "); elseprintf (" %. 4lf \ n ", solve (y);} return 0 ;}

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.