题目分析:
#include <iostream> #include <cmath> using namespace std; #define POW(x) ( (x) * (x) ) #define POW3(x) ( POW(x) * (x) ) #define POW4(x) ( POW(x) * POW(x) ) double y = 0; bool douEql ( double a,double b ) { if ( fabs( a - b ) <= 1e-6 ) return true; return false; } double cal ( double n ) { return 8.0 * POW4(n) + 7 * POW3(n) + 2 * POW(n) + 3 * n + 6 ; } double biSearch ( double l, double r ) { if ( douEql ( l,r ) ) { if ( douEql ( y, cal ( l ) ) ) return l; return -1; } double mid = ( l + r ) / 2.0; if ( douEql ( y, cal ( mid ) ) ) return mid; else if ( cal ( mid ) > y ) return biSearch ( l,mid - 0.0001 ); else return biSearch ( mid + 0.0001, r ); } int main () { int T; scanf ( "%d",&T ); while ( T -- ) { scanf ( "%lf",&y ); if ( cal(0) >= y && cal(100) <= y ) { printf ( "No solution!\n" ); continue; } double res = biSearch ( 0.0, 100.0 ); if ( res == -1 ) printf ( "No solution!\n" ); else printf ( "%.4lf\n",res ); } return 0; }
AC代码如下: