CF1C

CF last question is actually the first game of computational geometry.
This question of the test sites is more, so to write a solution to a problem.

  • Front cheese

    1. plane rectangular coordinate system points the distance formula : \ (L = \ sqrt {(X_1-X_2) ^ 2 + (Y_1-Y_2) ^ 2} \)
    2. Heron's formula : Knowing the three sides for calculating triangle area \ (S = \ sqrt {P (PA) (Pb) (PC)} \) (where \ (a, b, c \ ) of sides of a triangle, \ (P = \ FRAC {A + B + C {2}} \) )
    3. circumradius formula : \ (= R & lt \ 4S FRAC {ABC} {} \)
    4. Solutions triangles
    (triangular seeking to know the angle):
    \ (\ COS B = \ A {FRAC ^ 2 + C ^ 2-B ^ 2} {2AC} \)
    \ (\ COS A = \ FRAC {B ^ 2 + C ^ 2-A ^ 2} {2BC} \)
    \ (\ COS C = \ FRAC {a ^ 2 + b ^ 2
    -c ^ 2} {2ab} \) then \ (\ cos A, \ cos B, \ cos C \) into \ (\ arccos () \) determined angle
    (known seeking an angle on both sides of the third side)
    \ (C = \ sqrt {2 + a ^ B ^ 2-2ab \ COS C} \)
    5. The Euclidean algorithm (gcd): this question looks nothing, In particular it will be mentioned later.
  • specific methods

    : A look at FIG
    Here Insert Picture Description
    rear A in the figure, B, C is a given point, the same can be found that the regular polygon circumscribed circle of triangle, circle center O, AO = BO = CO, know circumradius formula can be obtained AO, BO, CO, in the solution will be drawn triangle \ (\ angle the AOB \) , \ (\ angle the BOC \) , and \ (\ angle the AOC \) (refer to FIG greater than \ (^ 180 \ CIRC \) of the angle) can be found a certain number of relationships between the three corners and three angles can be represented as an integer multiple of a corner, and the radius of the adjacent yellow angle, this angle is set \ (\ angle \ Alpha \) , then the figure \ (\ angle the AOB =. 3 * \ angle \ Alpha \) , \ (\ angle the BOC = 2 * \ angle \ Alpha \) , \ (\ angle the AOC =. 6 * \ angle \ Alpha \) , then \ (\ angle \ Alpha = GCD (\ angle the AOB, GCD (\ angle the BOC, \ angle the AOC)) \) , the three sides of the angle for each small triangle know all know, also know the number of triangles, the total area can be determined.
  • Code

#include<bits/stdc++.h>
using namespace std;
const double pi=3.1415926;
double mod(double a,double b)//小数取模
{
    return a-(int)(a/b)*b;
}
double gcd(double x,double y)//小数gcd
{
    if(y<=0.0001)return x;
    return gcd(y,mod(x,y));
}
double x,y,x2,y2,x3,y3;
int main()
{
    scanf("%lf%lf%lf%lf%lf%lf",&x,&y,&x2,&y2,&x3,&y3);
    //计算三角形三条边长
    double a=sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
    double b=sqrt((x-x3)*(x-x3)+(y-y3)*(y-y3));
    double c=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
    double p=(a+b+c)/2;
    double r=(a*b*c)/(4*sqrt(p*(p-a)*(p-b)*(p-c)));//通过r=(abc)/(4s)得出外接圆半径
    //分别求出以三条边为低,外接圆半径为腰的三角形的顶角角度
    double angle1=acos(1-(a*a)/(2*r*r));
    double angle2=acos(1-(b*b)/(2*r*r));
    double angle3=2*pi-angle1-angle2;
    double angle=gcd(angle1,gcd(angle2,angle3))/pi*180;//题目所示的以正多边形边长为低接圆半径为腰的三角形的顶角角度
    double side=sqrt(2*r*r-2*r*r*cos(angle/180*pi));//求出正多边形的边长
    double P=(r*2+side)/2;
    double S=sqrt(P*(P-r)*(P-r)*(P-side))/*三角形面积*/*(360/angle)/*三角形个数*/;//计算面积
    printf("%.6lf",S);//保留6位小数输出
    return 0;
}

Guess you like

Origin www.cnblogs.com/Sxy_Limit/p/12164957.html