• HDU 2199 Can you solve this equation?(二分精度)


    HDU 2199 Can you solve this equation?
     
     
    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.

    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),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!

    这种题一般都很注重精度的,可以拿两个端点来做验证,6的时候应该为0.0000,807020306的时候应该为100.0000
    其中while(ri-le<=0.000000001)这里的0尽量多一点,而判断的时候的0的个数要看情况,有些当满足
    ri-le<=0.000000001时,说不定判断还不满足。

    #include <iostream>
    #include <stack>
    #include <string.h>
    #include <stdio.h>
    #include<queue>
    #include<algorithm>
    #define ll long long
    using namespace std;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            double y;
            cin>>y;
            double le,ri,mid;
            le=0;ri=100;
            bool f=0;
            while(ri-le>=0.00000000000001)
            {
                mid=(le+ri)/2;
                //cout<<8*mid*mid*mid*mid+7*mid*mid*mid+2*mid*mid+3*mid+6-y<<endl;
                if(8*mid*mid*mid*mid+7*mid*mid*mid+2*mid*mid+3*mid+6-y<0.00001&&8*mid*mid*mid*mid+7*mid*mid*mid+2*mid*mid+3*mid+6-y>=0)
                {
                    f=1;
                    break;
                }
                else if(8*mid*mid*mid*mid+7*mid*mid*mid+2*mid*mid+3*mid+6-y<0)
                {
                    le=mid;
                }
                else
                    ri=mid;
            }
            if(f)
                printf("%.4lf
    ",mid);
            else
                printf("No solution!
    ");
        }
        return 0;
    }
     
  • 相关阅读:
    管道/重定向/环境变量
    用户和组命令
    常用命令
    系统监控及进程
    Centos硬件信息
    Centos系统信息及日志
    linux防火墙
    ipt_connlimit限制并发,ipt_recent限制单位时间内的请求数目
    apache添加mod_limitipconn限制单个ip并发连接数
    php核心技术与最佳实践知识点(下)
  • 原文地址:https://www.cnblogs.com/caiyishuai/p/13270919.html
Copyright © 2020-2023  润新知