HDU 2199 Can You solve this equation? (Two-point search)

Source: Internet
Author: User

Topic links

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 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); OutputFor each test case, you should just output one real number (accurate up to 4 decimal places), and which is the solution of the E Quation,or "No solution!", if there is No solution for the equation between 0 and 100. Sample Input2100-4 Sample Output1.6152No solution! The two-point search, precision see code. Always WA, can not find the wrong, and finally found that there is less an exclamation point! Oh, hang on. Judging the function's derivative function is greater than 0 on [0,100], so this function is judged by the monotonically increasing nature of [0,100].
#include <cstdio>#include<iostream>#include<string>#include<sstream>#include<cstring>#include<stack>#include<queue>#include<algorithm>#include<cmath>#include<map>#defineMS (a) memset (A,0,sizeof (a))#defineMSP Memset (Mp,0,sizeof (MP))#defineMSV memset (vis,0,sizeof (VIS))using namespacestd;#defineLOCALinty;DoubleFunDoublex) {    return 8*pow (x,4.0)+7*pow (x,3.0)+2*pow (x,2.0)+3*x+6;}voidsolve () {if(Fun (0) >y| | Fun -) <y) {printf ("No solution!\n"); return; }    DoubleA=0, b= -, Ans,m;  while(b-a>1e-6) {m= (a+b)/2; Ans=Fun (m); if(ans>y) b=m-1e-7; Elsea=m+1e-7; } m= (a+b)/2.0; printf ("%.4lf\n", M); return;}intMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endif //LOCAL    //Start    intN; CIN>>N;  while(n--) {cin>>y;    Solve (); }    return 0;}

HDU 2199 Can You solve this equation? (Two-point search)

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.