Ancient Berland Circus CodeForces - 1C

Meaning of the questions: given to the three vertices of a regular polygon, regular polygon seeking the minimum area.

Ideas: First, the smaller the area of ​​the smaller number of edges, so long as it is determined that the minimum number of edges comprise three vertices of a regular polygon can. This triangle regular polygon and add the same circle. Therefore, first find the radius of the circumscribed circle, and then three central angle is obtained, easy to get the central angle corresponding to the edges of the polygon may be divided by three central angle, so gcd three sides of the polygon is the central angle of the pair central angle, and in addition to what is obtained is 2π several polygon, then the area can be calculated

Heron's formula: p = (a + b + c) / 2, S = √p (pa) (pb) (pc) (a, b, c of the three sides of a triangle, S is the area of ​​the triangle) 

Seeking circumradius r = a * b * c / 4S 

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<stack>
#include<cstdlib>
#include<queue>
#include<set>
#include<string.h>
#include<vector>
#include<deque>
#include<map>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-4
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
typedef long long LL;
typedef long long ll;
const int MAXN = 1e6 + 5;
const int mod = 998244353;

struct node{
    double x,y;
};
double len(node a,node b) {
    double tmp = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
    return tmp;
}
double gcd(double x,double y) {
    while(fabs(x) > eps && fabs(y) > eps) {
        if(x > y)
            x -= floor(x / y) * y;
        else
            y -= floor(y / x) * x;
    }
    return x + y;
}
int main()
{
    node a,b,c;
    cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y;
    double lena = len(a,b);
    double lenb = len(b,c);
    double lenc = len(a,c);

    double p = (lena + lenb + lenc) / 2.0;
    double S = sqrt(p * (p - lena) * (p - lenb) * (p - lenc));
    double R = lena * lenb * lenc / (4.0 * S);
    double A = acos((lenb * lenb + lenc * lenc - lena * lena) / (2 * lenb * lenc));
    double B = acos((lena * lena + lenc * lenc - lenb * lenb) / (2 * lena * lenc));
    double C = acos((lena * lena + lenb * lenb - lenc * lenc) / (2 * lena * lenb));
    double PI = acos(-1.0);
    double n = PI / gcd(gcd(A,B),C);
    double ans = n / 2 * R * R * sin(2 * PI / n);
    printf("%.10f\n",ans);
}

 

Guess you like

Origin www.cnblogs.com/smallhester/p/11361273.html