What about poj 2420 a star not a tree? Ferma point, simulated annealing

Source: Internet
Author: User
/* Reference: locate the range of these vertices, and use two vertices (E1 and E2 in the Code). 2. Generate num vertices within the range (Num-customized) 3. For each generated vertex I, generate num points around it. If it is a bit better than I, replace it. 4. narrow the range D. If D is less than precision, exit. Otherwise, 35 is executed to traverse all num points, find the maximum value of Val */# include <iostream> # include <cstdio> # include <cstdlib> # include <cmath> # include <cstring> # include <string> # include <Algorithm> # include <set> # include <map> # include <ctime> using namespace STD; const int num = 30; const int rad = 1000; struct point {Double X, Y, Val; point () {} Point (double _ x, double _ y ): X (_ x), y (_ y) {}} P [101], may [num], E1, E2; int N; double DIS (point a, point B) {Return SQRT (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} double judge (point t) // evaluation function, get the evaluation value of point t Val {double Len = 0; For (INT I = 0; I <N; I ++) Len + = DIS (T, P [I]); Return Len;} double rand () {return rand () % (RAD + 1) /(1.0 * rad);} // randomly generate a floating point number of 0-1. Point rand_point (point a, point B) // At, point {point TMP = point (. X + (B. x-a.x) * rand (),. Y + (B. y-a.y) * rand (); TMP. val = judge (TMP); Return TMP;} void solve (double D) {for (INT I = 0; I <num; I ++) May [I] = rand_point (E1, E2); // Step 2 while (D> 0.1) // step 3 {for (INT I = 0; I <num; I ++) for (Int J = 0; j <num; j ++) {point TMP = rand_point (point (may [I]. x-D, may [I]. y-d), point (may [I]. X + D, may [I]. Y + D); If (TMP. val <may [I]. val) {may [I] = TMP ;}d * = 0.9;} double ans = 1ll <45; For (INT I = 0; I <num; I ++) if (may [I]. val <ans) ans = may [I]. val; printf ("% 0. f \ n ", ANS);} int main () {srand (time (0); e1 = point (-10001,-10001); E2 = point (10001,10001 ); while (scanf ("% D", & N )! = EOF) {for (INT I = 0; I <n; I ++) {scanf ("% lf", & P [I]. x, & P [I]. y); e1.x = min (e1.x, P [I]. x); // set the initial range to e1.y = min (e1.y, P [I]. y); e2.x = max (e2.x, P [I]. x); e2.y = max (e2.y, P [I]. y);} solve (max (e2.y-e1.y, e2.x-e1.x ));}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.