Zoj 1450 (http://blog.himdd.com /? P = 2666) Many templates can be used to calculate the intersection point of a straight line, and the circle center of an external triangle (external Center)

Source: Internet
Author: User
Question: Give You n points. Find the smallest circle to cover all points. Analysis: Minimum circular coverage. Magic random algorithms. When a point is added to a period in random order, the expected complexity is linear. Algorithm: A. Make Ci represent the smallest covered circle of the first I point. When a new point pi is added, if the pi is not in the Ci-1, the pi must be on the Ci boundary. B. Consider this problem again. Ci is the first I point that covers the smallest circle and p is on the Ci boundary! Similarly, if pi is not in the Ci-1 when new point pi is added, then pi must be on the Ci boundary. Then we include two points on the boundary of the smallest circle. C. Consider this problem again. Ci is the smallest covering circle of the first I point and there are two definite points on the boundary! At this time, let the pi and the two point on the boundary of the smallest circle. The O (N) method can determine the smallest circle. Analysis: analyze why it is linear. C is linear, which is obvious. B <-C in the process. Consider the probability of pi in the circle as (I-1)/I. The probability outside the circle is 1/I. Therefore, the expected complexity of adding pi is: (1-i)/I * O (1) + (1/I) * O (I) {the former does not enter C in the park, and only uses O (1 ). The latter enters C and uses the O (I) time} for analysis. The complexity is actually linear. A <-B is in the process. The method is the same, so that A <-B is still linear. Therefore, the complexity of the incredible minimum circular coverage becomes linear. The following program did not randomize the points first, because the data is usually random =! If the data is not random, you can use the shuffling function random_shuffle (p, p + n). For details, see: GU Yan's "Application of randomization in geometric issues" is in Baidu Library. # Include <iostream> # include <cstdio> # include <ctime> # include <cmath> # include <algorithm> using namespace std; const double eps = 1e-12; const int len = 100010; struct Point {double x, y;} p [len]; struct Line {Point a, B ;}; int dbcmp (double n) {return n <-eps? -1: n> eps;} double dis (Point a, Point B) {return sqrt (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} // calculates the intersection of two straight lines Point intersection (Line u, Line v) {Point ret = u. a; double t = (u. a. x-v.a.x) * (v. b. y-v.a.y)-(u. a. y-v.a.y) * (v. b. x-v.a.x)/(u. a. x-u. B .x) * (v. b. y-v.a.y)-(u. a. y-u. B .y) * (v. b. x-v.a.x); ret. x + = (u. b. x-u.a.x) * t; ret. y + = (u. b. y-u.a.y) * t; return ret;} // excircle of the triangle (excircle) Point center (Point a, Point B, Poin T c) {Line u, v; u. a. x = (. x + B. x)/2; u. a. y = (. y + B. y)/2; u. b. x = u. a. x + (u. a. y-a.y); u. b. y = u. a. y-(u. a. x-a.x), v. a. x = (. x + c. x)/2; v. a. y = (. y + c. y)/2; v. b. x = v. a. x + (v. a. y-a.y), v. b. y = v. a. y-(v. a. x-a.x); return intersection (u, v);} void min_cir (Point * p, int n, Point & cir, double & r) {random_shuffle (p, p + n ); cir = p [0]; r = 0; for (int I = 1; I <n; ++ I) {if (dbcmp (dis (p [I], cir) -r) <= 0) continue; cir = p [I]; R = 0; for (int j = 0; j <I; ++ j) {if (dbcmp (dis (p [j], cir)-r) <= 0) continue; cir. x = (p [I]. x + p [j]. x)/2; cir. y = (p [I]. y + p [j]. y)/2; r = dis (cir, p [j]); for (int k = 0; k <j; ++ k) {if (dbcmp (dis (p [k], cir)-r) <= 0) continue; cir = center (p [I], p [j], p [k]); r = dis (cir, p [k]) ;}}} int main () {int n; while (~ Scanf ("% d", & n), n) {for (int I = 0; I <n; ++ I) {scanf ("% lf ", & p [I]. x, & p [I]. y);} Point cir; double r; min_cir (p, n, cir, r); printf ("%. 2lf %. 2lf %. 2lf \ n ", cir. x, cir. y, r );}}

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.