HDU 2199
人生中第一道搜索题
精度精度、!!!
1 #include<iostream> 2 #include<algorithm> 3 #include<cmath> 4 #include<cstdio> 5 using namespace std; 6 double f(double x) 7 { 8 return 8*pow(x,4.0)+7*pow(x,3.0)+2*pow(x,2.0)+3*x + 6; 9 } 10 int main() 11 { 12 int n;cin >> n; 13 while(n--){ 14 double y;cin >> y; 15 if(f(0.0)<=y&&f(100.0)>=y){ 16 double left=0,right=100; 17 double mid; 18 while(right-left>1e-6){ 19 mid=(left+right)/2; 20 double ans=f(mid); 21 if(ans>y) right=mid+1e-7; 22 else left=mid-1e-7; 23 mid=(left+right)/2.0; 24 } 25 printf("%.4lf\n",(left+right)/2.0); 26 } 27 else cout << "No solution!\n"; 28 } 29 }