• Can you solve this equation?


    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;
    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
    100 -4
    Sample Output
    1.6152
    No solution!
    题意:利用二分法求解;
    解题思路:用最简单的二分就能过,但是!!!注意精度最少1e-6;
    感悟:终于知道学长说的,二分最蛋疼的就是控制精度了;
    代码:
    #include
    #include
    using namespace std;
    double iteration(double x)
     
        double fx;
        fx=8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;
        return fx;
    }
    int main()
    {
        //freopen("in.txt", "r", stdin);
        int n;
        double y,x1,x2,x;
        scanf("%d",&n);
        for(int i=0;i
        {
            scanf("%lf",&y);
            x1=-1;
            x2=101;
            if(y<6||y>807020306)
            {
                printf("No solution! ");
                continue;
            }//最大解和最小解判断有没有解
            else
            {
                while(true)
                {
                    x=(x1+x2)/2;
                    if(x2-x1<1e-6)//这里精度最小就得是1e-6
                    {
                        printf("%.4lf ",x);
                        break;
                    }
                    else
                    {
                        if(iteration(x)==y)
                        {
                            printf("%.4lf ",x);
                            break;
                        }
                        else if(iteration(x)
                            x1=x;
                        else if(iteration(x)>y)
                            x2=x;
                   }
                }
            }
         }
         return 0;
    }
  • 相关阅读:
    mybaits源码分析--事务管理(八)
    mybaits源码分析--binding模块(五)
    mybaits源码分析--自定义插件(七)
    mybaits源码分析--缓存模块(六)
    2021年9月
    golang-reflect实战ini配置文件
    ECC加密原理详解
    RFID 随手记
    计算机实现加法
    公钥加密算法 RSA
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/5781646.html
Copyright © 2020-2023  润新知