2001

来源:互联网 发布:wer机器人编程 编辑:程序博客网 时间:2024/05/16 19:21

2001

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>
 

简单题意:
给定一个方程,在0—100之间寻找解
思路:直接使用二分法即可;
AC代码:#include<cmath>
#include<cstdio>
#define eps 1e-8
double fun(double x)
{
    return 8*x*x*x*x + 7*x*x*x + 2*x*x + 3*x + 6;
}
int main()
{
    double y,a,b,m,d;
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lf",&y);
        if(y<6 || y>807020306)
        {
            printf("No solution!\n");
            continue;
        }
        a=0.0;
        b=100.0;
        while(b-a>eps)
        {
            m=(a+b)/2;
            if(fun(m)<y)
                            a=m;
                        else
                            b=m;
        }
        printf("%.4f\n",a);
    }
    return 0;
}

0 0
原创粉丝点击