Original question http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2199
Can you solve this equation?
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 8441 accepted submission (s): 3902
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 );
Outputfor each test case, You shocould 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
// A simple binary. First, you can determine which range has a certain solution. // then, you can narrow down the scope. # include <stdio. h> # include <stdlib. h> # include <malloc. h> # include <limits. h> # include <ctype. h> # include <string. h> # include <string> # include <math. h> # include <algorithm> # include <iostream> # include <stack> # include <queue> # include <deque> # include <vector> # include <set> # include <map> using namespace STD; __int64 y; const double D = 1e-8; double F (double m) {If (Y-(8 * m + 7 * m * M + 2 * m + 3 * m + 6)> = 1e-20) {return 1;} else {return 0 ;}} // D // ouble F1 (Double X) {// return (8 * x + 7 * x + 2 * x + 3 * x + 6-y ); //} int main () {int t; while (~ Scanf ("% d", & T) {While (t --) {scanf ("% i64d", & Y); If (Y <6 | Y> 807020306) {printf ("no solution! \ N "); continue;} else {double L = 0.0; double r = 100.0; int flag = 0; while (R-l> D) {double mid = (L + r)/2; If (f (MID) = 1) {L = mid;} else {r = mid ;}} printf ("%. 4lf \ n ", L); // If (flag = 0) {// printf (" no solution! \ N "); // }}} return 0 ;}