题目:http://acm.hdu.edu.cn/showproblem.php?pid=2199
二分,注意精度就好
#include <iostream> #include <cmath> using namespace std; double Y; double cal(double x) { return 8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6; } double BinarySearch(double low,double heigh) { if(low>=heigh) return 0; double mid = (low+heigh)/2; // printf("%lf中值%lf下界%lf上界%lf ",mid,res(mid),low,heigh); if(abs(cal(mid)-Y)<=0.00001) return mid; if(cal(mid)<Y) return BinarySearch(mid,heigh); else return BinarySearch(low,mid); } int main(int argc, const char *argv[]) { int n; cin>>n; while(n--) { cin>>Y; if(cal(0)>Y||cal(100)<Y) { printf("No solution! "); } else { double rs = BinarySearch(0,100); printf("%.4lf ",rs); } } return 0; }