Hdu3932 minimum circular coverage-simulated annealing-3 +

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3932

Question: Give a bunch of points and find the least distance between a point and these points... Precision: 0.1

 

Analysis:

This question was originally a template question with the smallest circle covered... At the beginning, I thought of the simulated annealing of ferma points .. It took me one afternoon to write it out ....

At first, we used a four-direction search to determine how to reduce the step size. Later, we changed the step size to eight directions, but the accuracy was not adjusted to 10e-9... Finally, we changed it to many points around the current point (it seems that 60 points are used) to judge the accuracy. It only takes 0.1... I cannot explain the reason...

I am afraid to write simulated annealing in the future .. The precision of the last time the Fuzhou field competition has been adjusted for so long is dangerous ..... Yes !!!!!

 

Code:

# Include <iostream> # include <cmath> using namespace STD; const double Pi = 3.141592654; const int n = 1010; struct point {Double X, Y;} p [N], mn, MX, mid, mid1; int n, x, y; double ans, ans1; double DIS (point a, point B) {return (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} void CAL (Double X, Double Y) {int I, j; double MX = 0, TMP; point TP; TP. X = x; TP. y = y; for (I = 0; I <n; I ++) {TMP = DIS (P [I], TP); If (TMP> MX) MX = TMP;} If (Ans1> MX) {ans1 = Mx; mid1 = TP ;}} int main () {int I, j, k; double width; while (scanf ("% d", & X, & Y, & N )! = EOF) {Mn. X = Mn. y = 0x7fffffff; MX. X = mx. y = 0; for (I = 0; I <n; I ++) {scanf ("% lf", & P [I]. x, & P [I]. y); If (P [I]. x <Mn. x) Mn. X = P [I]. x; If (P [I]. Y <Mn. y) Mn. y = P [I]. y; If (P [I]. x> MX. x) MX. X = P [I]. x; If (P [I]. y> MX. y) MX. y = P [I]. y;} mid. X = (Mn. X + mx. x)/2; mid. y = (Mn. Y + mx. y)/2; mid1 = mid; width = mx. x; If (MX. y> width) width = mx. y; ans1 = 0; for (I = 0; I <n; I ++) {If (DIS (MID, P [I])> ans1) ans1 = DIS (MID, P [I]);} ans = ans1; doub Le II; while (1) {/* CAL (MID. X-width, mid. Y); // you can determine four keys, but not eight .. Even if the precision is adjusted to 10e-9cal (MID. X + width, mid. y); CAL (MID. x, mid. y-width); CAL (MID. x, mid. Y + width); CAL (MID. x-width, mid. y-width); CAL (MID. x-width, mid. Y + width); CAL (MID. X + width, mid. y-width); CAL (MID. X + width, mid. Y + width); */For (II = 0; II <= 2 * PI; II + = 0.1) // rotate multiple points to determine .. {CAL (MID. X + width * Cos (II), mid. Y + width * sin (ii);} If (ans-ans1 <0.1 & width <0.001) break; If (ans1 <ans) {ans = ans1; Mid = mid1 ;} elsewidth * = 0.5;} printf ("(%. 1lf, %. 1lf ). \ n ", mid. x, mid. y); printf ("%. 1lf \ n ", SQRT (ANS);} return 0 ;}

 

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.