菜鸟能力有限,借鉴了大神的博客:http://blog.csdn.net/shiyuankongbu/article/details/8434560
题意:已知三个点,求这三个点围成的正多边形面积最小。
思路:无,先存在博客里面,以后再来看看!
大神的代码:
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define pi 3.1415926
#define eps 10e-3
typedef struct point
{
double x,y;
};
double area(double x0,double y0,double x1,double y1,double x2,double y2)
{
return 0.5*fabs(x0*y1+x2*y0+x1*y2-x2*y1-x0*y2-x1*y0);
}
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
point p[3];
bool is_ok(int n,double jiao)
{
double cnt=n*jiao/pi;
double pnt=floor(cnt+eps);
if(cnt-pnt<eps)
return true;
return false;
}
int main()
{
for(int i=0;i<3;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
double a=dis(p[0],p[1]);
double b=dis(p[0],p[2]);
double c=dis(p[1],p[2]);
double A=acos((b*b+c*c-a*a)/2/b/c);
double B=acos((a*a+c*c-b*b)/2/a/c);
double C=acos((b*b+a*a-c*c)/2/b/a);
double r=a*b*c/area(p[0].x,p[0].y,p[1].x,p[1].y,p[2].x,p[2].y)/4;
//double jiao=max(A,max(B,C)); 开始我觉得下面的is_ok函数只要判断jiao就可以了
// 其实还是会WA 第五组数据。。。WA的时候答案是输出的两倍,Wa的厉害了
int n;
for(n=3;n<=100;n++)
if(is_ok(n,A)&&is_ok(n,B)&&is_ok(n,C))
break;
double tag=2*pi/n;
double Area=n*r*r*sin(tag)/2;
printf("%.8lf\n",Area);
return 0;
}