题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2199
//二分法求零点 #include<iostream> #include<cmath> #include<iomanip> using namespace std; int t; double x,y; //f(x)递增 double f(double x){ return 8*pow(x,4)+7*pow(x,3)+2*x*x+3*x+6-y; } double lt,rt,mid; double tmp; double ans; int main (){ cin>>t; while(t--){ cin>>y; if(y<6) //f(0)>0 cout<<"No solution!"<<endl; else if(f(100)<0) cout<<"No solution!"<<endl; else{ lt=0; rt=100; while(rt-lt>1e-8) { mid=(lt+rt)/2; tmp=f(mid); if(tmp>0) rt=mid; else if(tmp<0) lt=mid; else rt=lt=mid; } ans=mid; cout<<fixed<<setprecision(4); cout<<mid<<endl; } } return 0; }