Dichotomous answer template

The answer is to solve half the minimum of the maximum or minimum of the maximum common solution, the following templates:

the while ( rl is an>. 1 ) { 
        MID = (L + R & lt) >> . 1 ;
         IF (Judge (MID)) { 
            L = MID;
                 // left boundary of the right 
        } the else { 
            R & lt = MID;
                 // right boundary of the left 
        } 
    } 
    IF (Judge (R & lt)) COUT << R & lt;
     the else COUT << L;

 

Guess you like

Origin www.cnblogs.com/MS903/p/11247826.html