cf2c (simulated annealing stepsize control

https://www.luogu.org/problem/CF2C

The meaning of problems: there are three in the plane portion without common circle, equal to that required to give the upper plane of the three circles tangent angle. (If the answer is not to meet the conditions, will not be printed

Ideas: simulated annealing algorithm can be used to enumerate the answer point, can be had, however, should not be a positive solution. First set up an optimal solution and the initial steps, and then continue with the current step search for a solution to update the optimal answer, if the answer can not be updated, the step size is halved and then search until the end of the algorithm accuracy requirements.

#include <cstdio> 
#include <the cmath> 
const = Double the EPS-1E. 5; // control accuracy 
struct {Point 
    Double X, Y; 
    Double R & lt; 
} P [. 3]; 
Double the Get (Double X, Y Double, Point const b) {// find the distance between two points 
    return sqrt ((xb.x) * (xb.x) + (yb.y) * (yb.y)); 
} 
Double the Check (Double X, Y Double) {// evaluation function 
    double t [3], delta [ 3], ret = 0.0; // t for the current perspective, delta represents an error value 
    for (int I = 0; I <. 3; ++ I) 
        T [I] the Get = (X, Y, P [I]) / P [I] .r; 
    for (int I = 0; I <. 3; I ++) { 
        Delta [I] = T [I] -t [(I + 1'd)%. 3]; 
        RET = Delta + [I] * Delta [I]; 
    } 
    return RET; // return error square sum 
} 
int main () { 
    BOOL Mark; 
    Double X = 0.0, Y = 0.0; 
    for (int I = 0; I <. 3; I ++) { 
        Scanf ( "LF%%% LF LF", & P [I] .x, & P [I] .y, P & [I] .r); 
        X = P + [I] .x /. 3; 
        Y = P + [I] .y /. 3; // set the center of gravity of the approximate solution of a triangle formed of three round heart 
    } 
    for (Double t = 1.0, delta; t> EPS;) {// initial step size. 1 
        mark = 0; // tag search 
        Delta = the Check (X, Y); 
        IF (the Check (X + T, Y) <Delta) { // Search better solution 
            X = T +; 
            Mark =. 1; 
        } 
        the else IF (the Check (XT, Y) <Delta) { 
            X-= T; 
            Mark =. 1; 
        } 
        the else IF (the Check (X, Y + T) < Delta) { 
            Y = T +; 
            Mark =. 1; 
        }
        IF the else (the Check (X, YT) <Delta) {
            T = Y-; 
            Mark =. 1; 
        } 
        IF (! Mark) // search step size is less than 
            T / 2 =; 
    } 
    IF (FABS (the Check (X, Y)) <the EPS) // Check 
        printf ( "% % .5lf .5lf ", X, Y); 
    return 0; 
}

 

Guess you like

Origin www.cnblogs.com/wzgg/p/11518734.html