题意:给定一个正多边形的三个顶点,求这个正多边形的最小面积。
思路:首先,边数越小面积越小,所以只要确定出包含这三个顶点的边数最小的正多边形即可。这个三角形和正多边形外接同一个圆。所以先求出外接圆的半径,再求出三个圆心角,易得这个多边形的边所对应的圆心角可被这三个圆心角整除,所以三个圆心角的gcd就是多边形边所对的圆心角,然后2π除一下就得到是几边形,之后就可计算面积了
海伦公式: p=(a+b+c)/2,S=√p(p-a)(p-b)(p-c)(a,b,c为三角形的三边,S为三角形面积)
求外接圆半径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("********* ") #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 ",ans); }