Portal
Test instructions
The coordinates of a regular polygon three vertices are given, and the minimum area of the regular polygon is obtained.
Analysis
For the sake of convenience, the definition of the regular polygon unit central angle U is the center angle of the circumscribed circle of an edge of regular polygon (that is, the center angle of a chord of circumscribed circle).
(1) The number of sides of the polygon is unknown, but its circumscribed circle is deterministic. The circumscribed circle of a polygon is the circumscribed circle of a triangle consisting of three vertices. The smallest area is the least number of edges, the unit central angle maximum.
(2) Set the triangle on either side of the center angle is A1, A2 (expressed in radians), the largest unit center angle is
U= GCD (A1, A2, 2pi-a1-a2).
Ideas
(1) Three-point fixed circle. The perpendicular bisector intersection of two segments is the center point.
If the coordinates of the line AB end points are a (x1, y1), B (x2, y2), then the perpendicular bisector equation of AB is
2 (X1-X2) x + 2 (y1-y2) y = (x1^2+y1^2) – (x2^2+y2^2)
This type of form is very symmetrical and easy to remember.
The coordinate of the center of the equation is solved.
(2) The greatest common divisor of two positive real numbers (GCD).
(3) To seek the area of regular polygon.
1#include <bits/stdc++.h>2 using namespacestd;3 #defineX First4 #defineY Second5 #defineMP Make_pair6 #defineDis2 (P) (P.X*P.X+P.Y*P.Y)7 #defineDet (i, J) (Eq[0][i]*eq[1][j]-eq[0][j]*eq[1][i])8 #defineAng (P) atan2 (P.Y, p.x)9 #defineEPS 1e-4Ten #definePI 3.14159263558979323846 OnetypedefDoubledb; Atypedef PAIR<DB, Db>P; -P p[3]; - //Make sure, your algorithm is correct the db Get_ang (P v1, p v2) { - returnACOs (v1. X*v2. X+v1. Y*v2. Y)/Dis2 (v1)); - } - P Get_center () { +DB eq[2][3]; - for(intI=0; i<2; i++){ +eq[i][0]=2* (P[i). x-p[i+1]. X); Aeq[i][1]=2* (P[i). y-p[i+1]. Y); ateq[i][2]=dis2 (P[i])-dis2 (p[i+1]); - } - returnMP (Det (2,1)/det (0,1), Det (0,2)/det (0,1)); - } - -Poperator- (ConstP &a,ConstP &b) { in returnMP (A.x-b.x, a.y-b.y); - } to + db gcd (db A, db b) { - returnB<eps?A:GCD (b, Fmod (A, b)); the } * $ intMain () {Panax Notoginseng //freopen ("in", "R", stdin); - for(intI=0; i<3; i++) thescanf"%LF%LF", &p[i]. X, &P[i]. Y); +P center=Get_center (); AP v[3]; the for(intI=0; i<3; i++) +v[i]=p[i]-Center; -DB A1=get_ang (v[0], v[1]); $DB A2=get_ang (v[0], v[2]); $DB a3=2*pi-a1-A2; -DB tmp=gcd (GCD (A1, A2), A3); -DB Res=pi/tmp*dis2 (v[1])*sin (tmp); theprintf"%.8f\n", res); - return 0;Wuyi}
P.S. This problem also has a simpler solution, do not need to seek circumscribed circle center coordinates, do not need to seek the center angle. Have the following conclusions
The a,b,c (expressed in radians) of the triangular three angles of the three points given in the problem is the maximum value for u
2*GCD (A, B, c) (this formula is consistent with the expression given above), A, B, C can be obtained by the string theorem, in addition to the Triangle circumscribed circle radius r, using the formula R = abc/4s, A, B, C for the three-side length, S is the area.
Codeforces 1C Ancient Berland Circus