HDU 1001 Can you solve this equation?

来源:互联网 发布:广州汇丰软件 编辑:程序博客网 时间:2024/05/23 00:11
Problem Description
Now,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;<br>Now please try your lucky.
 

Input
The 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 should 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
2<br>100<br>-4<br>
 

Sample Output
1.6152<br>No solution!<br>
 题目大意:求函数的解
解题思路:套二分模板
感想:……
AC代码:
#include<iostream>
#include<fstream>
#include<cmath>
using namespace std;
int main()
{
    long long int n;
    cin >> n ;
    while(cin >> n)
    {
        double min = 0 , max = n;
        double mid ;
        double res = 1 ;
        if(n>=0&&n<=5||n > 807020306) goto p;
        while(min <= max)
        {
            mid = (min + max)/2;
            double x = mid ;
            if(fabs((8 * x * x * x * x + 7 * x * x * x + 2 * x * x + 3 * x + 6) - n) < 1e-5){
                res = x ;
                printf("%.4f\n",res);
                break;
            }
            if(8 * x * x * x * x + 7 * x * x * x + 2 * x * x + 3 * x + 6 > n)
                max = mid ;
            else 
                 min = mid ;
        }
        p:if(res == 1) cout << "No solution!\n" ;
    }
    return 0;
}
0 0