1 //Accepted 0 KB 60 ms 2 //给出正多变形上的三个点,求正多形的最小面积 3 //记三个点之间的距离a,b,c; 4 //由余弦定理得cosA 5 //从而可求出sinA,和正多边形所在外接圆的半径r 6 //设三条边所对的圆心角为:theta1,theta2,theta3 7 //则正多边形所对的圆心角为gcd(theta1,gcd(theta2,theta3)) 8 //其中gcd(theta1,theta2)为求两个浮点数的最大公约数 9 //至此我们可以根据正多边形所在外接圆的半径r和圆心角求出正多边形的面积 10 #include <cstdio> 11 #include <cstring> 12 #include <iostream> 13 #include <queue> 14 #include <cmath> 15 #include <algorithm> 16 using namespace std; 17 const double Pi=acos(-1.0); 18 /** 19 * This is a documentation comment block 20 * @authr songt 21 */ 22 struct Point 23 { 24 double x,y; 25 }p[3]; 26 double getDis(Point p1,Point p2) 27 { 28 return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); 29 } 30 double gcd(double a,double b) 31 { 32 if (fabs(b)<1e-4) return a; 33 if (fabs(a)<1e-4) return b; 34 return gcd(b,fmod(a,b)); 35 } 36 void slove() 37 { 38 double a=getDis(p[1],p[2]); 39 double b=getDis(p[1],p[3]); 40 double c=getDis(p[2],p[3]); 41 double cosA=(b*b+c*c-a*a)/(2*b*c); 42 double sinA=sqrt(1-cosA*cosA); 43 double r=a/(2*sinA); 44 //printf("r=%lf\n",r); 45 double thetaA=2*asin(a/(2*r)); 46 double thetaB=2*asin(b/2/r); 47 //double thetaC=2*asin(c/2/r); 48 double thetaC=2*Pi-thetaA-thetaB; 49 //printf("%lf\n",thetaA+thetaB+thetaC); 50 double theta=gcd(thetaA,gcd(thetaB,thetaC)); 51 //printf("theta=%lf\n",theta); 52 //printf("Pi=%lf\n",Pi); 53 double s=2*Pi/theta*r*r/2*sin(theta); 54 printf("%.6lf\n",s); 55 } 56 int main() 57 { 58 while (scanf("%lf%lf%lf%lf%lf%lf",&p[1].x,&p[1].y,&p[2].x,&p[2].y,&p[3].x,&p[3].y)!=EOF) 59 slove(); 60 return 0; 61 }
时间: 2024-10-19 13:20:40