UVa10341 Solve It
对函数求一阶导数,<0,说明函数是递减的。
在[0,1]区间内二分答案,如果f(m)<0, y = m; 否则x = m;
注意无解情况的判断条件。
double f0 = f(0), f1 = f(1); if ( f0*f1 > 0 ) puts ("No solution" ); else { double x = 0, y = 1, m; while ( y-x > eps ) { m = x + (y-x)/2; if ( f(m) < eps ) y = m; else x = m; //if ( f(m) > 0 ) x = m; else y = m; } printf ( "%.4lf\n", x ); }