CF 1C

Ideas (cut in according to the special conditions of the topic):

1. See that the number of edges <=100 ——> can be enumerated

2. See the regular polygon -> study the angle between the vertices of the regular polygon (X, no obvious law) The regular polygon is on the circle (√) -> three points are on the circle

Therefore, the smallest circle can be found by finding the center of the circle, calculating the included angle, enumerating the number of sides, and checking whether it is a multiple of the minimum angle, so as to obtain the area

 

note:

1. Special judgment slope

2. The error range should not be too large, metaphysics

 

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m,a,ans,ans2;
double iptf1x,iptf2x,iptf3x,iptf1y,iptf2y,iptf3y;
int i,j,k;

bool equ(double a,double b)
{
//printf("%.3f %.3f %.3f\n",a,b,fabs(a-b));
    if(fabs(a-b)<0.0001)return true;
    return false;
}
int main()
{
    scanf("%lf%lf%lf%lf%lf%lf",&iptf1x,&iptf1y,&iptf2x,&iptf2y,&iptf3x,&iptf3y);
    
double mid12x=(iptf1x+iptf2x)/2,mid12y=(iptf1y+iptf2y)/2;
double K12;
if(equ(iptf1y-iptf2y,0))K12=999999999;
else K12=-(iptf1x-iptf2x)/(iptf1y-iptf2y);

double B12=mid12y-K12*mid12x;
//特判水平竖直 
double mid23x=(iptf2x+iptf3x)/2,mid23y=(iptf2y+iptf3y)/2;
double K23;
if(equ(iptf2y-iptf3y,0))K23=999999999;
else K23=-(iptf2x-iptf3x)/(iptf2y-iptf3y);

double B23=mid23y-K23*mid23x;
double X=(B23-B12)/(K12-K23);
double Y=X*K12+B12;
//换系 
iptf1x=iptf1x-X;
iptf1y=iptf1y-Y;
iptf2x=iptf2x-X;
iptf2y=iptf2y-Y;
iptf3x=iptf3x-X;
iptf3y=iptf3y-Y;

double r2=fabs(iptf1x*iptf1x+iptf1y*iptf1y);
double cos12=(iptf1x*iptf2x+iptf1y*iptf2y)/r2;
double ang12=acos(cos12);
double cos23=(iptf2x*iptf3x+iptf2y*iptf3y)/r2;
double ang23=acos(cos23);
double cos13=(iptf1x*iptf3x+iptf1y*iptf3y)/r2;
double ang13=acos(cos13);
//printf("%.3lf %.3lf %.3lf %.3lf %.3lf \n",X,Y,ang12/3.1415926*180,ang23/3.1415926*180,ang13/3.1415926*180);    

//Enumerate the number of sides
for(i=3;i<=100;i++)
{//
//Determine the angle size
double bz=3.1415926535793*2/i;//printf("%d %.9lf\n", i,ang12- (bz* (double)((int)(ang12/bz))));

if(equ(ang12- (bz* (double)((int)(ang12/bz+0.00001))),0))
if(equ(ang23- (bz* (double)((int)(ang23/bz+0.00001))),0))
if(equ(ang13- (bz* (double)((int)(ang13/bz+0.00001))),0))    
{
    printf("%.6lf",(double)i*fabs(sin(bz)*r2)/2);
    return 0;
}

}
}
 

Guess you like

Origin blog.csdn.net/haobang866/article/details/114583345