• hdu 2199 Can you solve this equation?


    #include<stdio.h>
    #include<queue>
    #include<algorithm>
    #include<string.h>
    #include<iostream>
    using namespace std;
    
    double y;
    double fcn(double x)
    {
        double t=8*x*x*x*x+7*x*x*x+2*x*x+3*x+6-y;
        return t;
    }
    
    int main()
    {
        int t;
        double x1,x2,x;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%lf",&y);
            x1=0,x2=100;
    
            if(fcn(x1)>0&&fcn(x2)>0)
            {
                printf("No solution!
    ");
                continue;
            }
            if(fcn(x1)<0&&fcn(x2)<0)
            {
                printf("No solution!
    ");
                continue;
            }
    
            if(fcn(x1)==0)
            {
                printf("%.4f
    ",x1);
                continue;
            }
            if(fcn(x2)==0)
            {
                printf("%.4f
    ",x2);
                //printf("%.2lf
    ",fcn(x2));
                continue;
            }
            int f=0;
            while(x2-x1>1e-10)
            {
                x=(x1+x2)/2;
                double t1,t2,t3;
                t1=fcn(x1);
                t2=fcn(x);
                t3=fcn(x2);
                if(fcn(x1)==0)
                {
                    f=1;
                    break;
                }
                if(fcn(x2)==0)
                {
                    f=2;
                    break;
                }
                if(t1>0&&t2<0) x2=x;
                else if(t1<0&&t2>0) x2=x;
                else if(t2>0&&t3<0) x1=x;
                else if(t2<0&&t3>0) x1=x;
                //printf("%.4f
    ",fcn(x1));
            }
            if(f==1) printf("%.4f
    ",x1);
            else printf("%.4f
    ",x2);
        }
        return 0;
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

  • 相关阅读:
    MySQL:解决脏读问题
    MySQL:隔离性问题(脏读)&回滚演示
    MySQL: Mysql 事务隔离级别
    MySQL:数据库事务
    GRE Vocabulary:sedulous
    MySQL:SQL约束
    GRE Vocabulary:pall
    MySQL:DQL操作单表
    MySQL: DQL 查询表中数据
    MySQL:DML操作 表中数据
  • 原文地址:https://www.cnblogs.com/xryz/p/4848019.html
Copyright © 2020-2023  润新知