(Hdu step 4.1.1) Can you solve this equation? (Using the bipartite Method to Solve the solution of the equations), hduequation

Source: Internet
Author: User

(Hdu step 4.1.1) Can you solve this equation? (Using the bipartite Method to Solve the solution of the equations), hduequation

Question:

Can you solve this equation?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 915 Accepted Submission (s): 436
 
Problem DescriptionNow, given the equation 8 * x ^ 4 + 7 * x ^ 3 + 2 * x ^ 2 + 3 * x + 6 = Y, can you find its solution between 0 and 100;
Now please try your lucky.
InputThe first line of the input contains an integer T (1 <= T <= 100) which means the number of test cases. then T lines follow, each line has a real number Y (fabs (Y) <= 1e10 );
Output
For each test case, you shoshould just output one real number (accurate up to 4 decimal places), which is the solution of the equation, or "No solution !", If there is no solution for the equation between 0 and 100.
Sample Input
2100-4
 
Sample Output
1.6152No solution!
 
AuthorRedow
 
Recommendlcy


Question Analysis:

Simple question. Returns the solution of a system of equations by using the bipartite method. The premise for determining the solution of a equations using the bipartite method is that the equation has monotonicity.


The Code is as follows:

/**. Cpp ** Created on: February 16, 2015 * Author: Administrator */# include <iostream> # include <cstdio> # include <cmath> using namespace std; const double delta = 1e-6; // 1e10 represents 10 ^ 10 double function (double x) {return 8 * pow (x, 4.0) + 7 * pow (x, 3) + 2 * pow (x, 2) + 3 * x + 6;}/*** use the bipartite method to solve the equations * y: number on the right of the equations */double work (double y) {double mid; double left = 0; double right = 100; while (right-left> delta) {// if the index on the right is greater than the index on the left Index large mid = (left + right)/2; // calculate the intermediate value if (function (mid) <y) {// if y is greater than the intermediate value... note that left = mid + (1e-7); // move the left index. Note that the offset used here should be smaller than the above} else {// otherwise right = mid-(1e-7 ); // move the index on the right} return (left + right)/2; // return the final value} int main () {int t; scanf ("% d ", & t); while (t --) {double y; // scanf ("% d", & y); cin> y; if (function (0) <= y & y <= function (100) {printf ("%. 4lf \ n ", work (y); // printf (" %. 4lf \ n ", find (y);} else {printf (" No solution! \ N ") ;}} 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.