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)