hdu 2199 can you solve this equation

/*
13.08.09
这个是二分二分二分。因为x>0的时候函数是递增的,所以可以用二分
然后要注意的就是精度的问题
1.除法运算法:/ 若俩操作数均为int、则结果为取整;任意一个为浮点数,则结果为浮点数
2.^ 这个貌似不是求幂运算符了,而是异或,所以不能用
3.我擦连continue都记错了
*/

#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;

double calculate(double x)
{
       return (8*x*x*x*x + 7*x*x*x + 2*x*x + 3*x + 6);  
//       return (8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6);
}

int main()
{
    int cas;
    cin >> cas;
    while (cas--)
    {
          double y;
          cin >> y;
          if (y>calculate(100) || y<calculate(0))
          {
                               printf ("No solution!\n");
                               continue;
          }
          double lef,rig,mid;
          lef=0.0;rig=100.0;
          while (fabs(y-calculate(mid))>1e-5)
          {
                mid=(lef+rig)/2.0;
                if (y>calculate(mid)) lef=mid;
                else if (y<calculate(mid)) rig=mid;
          }
          printf ("%.4f\n",mid);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值