It is limited, at the problem is not the solution, a lot of understanding
Thank you for watching this konjac
Topic : Portal
Roughly simulated annealing explain I will not repeat them here, if in doubt please see here
code:
#include <. bits / STDC H ++> #define Down 0.996 // slowly cooling the using namespace STD; int n-; struct Node { int X; int Y; int W; } Object [ 2005 ]; // able to save the coordinates of the object double ANSx, ansy, Use the ANSW command; // final answer Double energy ( Double X, Double Y) // according to the knowledge of physics, the smaller the sum, the more stable energy { Double R & lt = 0 , DX, Dy; for ( int A =. 1 ; A <= n-; A ++ ) { DX = X- Object [A] .x; Dy = Y- Object [A] .y; R & lt + = sqrt (DX DX * * + Dy Dy) * Object [A] .W; } return R & lt; } void SA () // simulated annealing { Double T = 3000 ; // temperature is sufficiently high the while (T> 1E- 15 ) // slightly greater than 0 { // generate [-T * RAND_MAX , T * RAND_MAX) random variation range (RAND (): [0, RAND_MAX)) // RAND () a random number, the maximum value RAND_MAX random doubleANSx + = EX (RAND () * 2 -RAND_MAX) * T; // randomly generated new answer Double EY ansy + = (RAND () * 2 -RAND_MAX) * T; Double EW = Energy (EX, EY); Double de EW- = Use the ANSW command; IF (de < 0 ) // If this answer more preferably, accept { ANSx = EX; ansy = EY; Use the ANSW command = EW; } the else IF (exp (-DE / T) * and RAND_MAX> RAND ( )) // probability exp (-Δt '/ T) accepts S' as a new current solution S. // otherwise accepted according to the probability of a polynomial { ANSx = EX; ansy = EY; } T * = ; Down } } void Solve () // probability annealing run a few times, to increase the optimal solution { SA (); SA (); SA (); SA (); } int main () { CIN >> n-; for ( int A = . 1 ; A <= n-; A ++ ) { Scanf ( " % D% D% D " , & Object [A] .x, & Object [a] .y, &Object [A] .W); ANSx + = Object [A] .x; ansy + = Object [A] .y; } ANSx / = n-; // to answer as the initial average ansy / = n-; Use the ANSW command = Energy (ANSx, ansy); Solve (); the printf ( " % .3lf .3lf% \ n- " , ANSx, ansy); // Skip output return 0 ; }