/*
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;
}
hdu 2199 can you solve this equation
最新推荐文章于 2021-08-25 20:34:03 发布