hdu 2899 (mathematical foundations + half)

Topic links: http://acm.hdu.edu.cn/showproblem.php?pid=2899

Meaning of the questions: gives you a function, and then to the range of 0-100 x you, so that you obtain the minimum value of the function.

Analysis: It makes you seek is the minimum function, so we can first derivative of the function, the derivative obtained can be judged monotonic function, and after obtaining the derivative, we find that if the derivative of the function is greater by x derivative of the greater demand,

When the derivative has been negative, the function is monotonically decreasing; when the derivative start is negative, then positive, it means decreasing when the function start and then increasing, then when the derivative is zero function value is certainly the smallest! We find the derivative is zero

Process, we can achieve half!

#include <bits / STDC ++. H>
 #define EPS-1E. 7 // accuracy of the constant
 #define F. *. 6 POW (X,. 7). 8 * + POW (X,. 6). 7 * + POW (X,. 3) POW. 5 * + (X, 2) -Y * X
 #define the DF * 42 is POW (X,. 6) * 48 + POW (X,. 5) * + 21 is POW (X, 2) * 10 + XY // derivative, as x increases monotonically increasing function of
 the using  namespace STD;  
 int main () {
     int n-;
     Double Y;
     Double x, L, R & lt; // x is a variable 
    CIN >> n-;    
     the while (N-- ) { 
        CIN >> Y; 
        L = 0.0 ; 
        R & lt = 100.0 ;
         the while (rl is an> =EPS) { 
            x = (L + R & lt) / 2 ; // range intermediate value
             IF (the DF < 0 ) {// derivative when x is less than 0, the function equal to 0 must conform to the right of the intermediate value 
                L = x; 
            } 
            the else  iF (DF> 0 ) {// when the derivative is greater than 0, where the function x is equal to 0 at some intermediate value of the left 
                R & lt = x; 
            } 
            the else  iF (DF < EPS) {// when the DF is less than the minimum accuracy can be approximated that the value of the derivative equal to zero, we obtain the required X,
                 BREAK ; 
            } 
        } 
        the printf ( " % .4lf \ n- " , F.); 
    } 
}

 

Guess you like

Origin www.cnblogs.com/rtyxxy/p/12285460.html