http://acm.hdu.edu.cn/showproblem.php?pid=2199
找到方程的解,直接二分,注意精度
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> using namespace std ; const double eps=1e-8 ; double f(double x) { return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6 ; } int main() { int t ; double mid ; scanf("%d",&t) ; while(t--) { double y ; scanf("%lf",&y) ; double a=0.0,b=100.0 ; if(f(a)>y || f(b)<y) { puts("No solution!") ; continue ; } while(b-a>eps) { mid=(a+b)/2 ; if(f(mid)>y) b=mid ; else a=mid ; } printf("%.4lf\n",mid) ; } return 0 ; }