AC日记——codeforces Ancient Berland Circus 1c

时间:2021-10-25 21:21:08

1C - Ancient Berland Circus

思路:

  求出三角形外接圆;

  然后找出三角形三条边在小数意义下的最大公约数;

  然后n=pi*2/fgcd;

  求出面积即可;

代码:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define INF (1e9)
#define eps (1e-4)
#define pi (3.1415926535) struct point
{
double x,y;
};
struct point ai[]; struct line {
double k,b; line *another; void updata(struct point a,struct point bb)
{
another=new line;
if(a.x==bb.x) k=INF,b=a.x;
else
{
if(a.y==bb.y) k=,b=a.y;
else
{
k=(bb.y-a.y)/(bb.x-a.x);
b=a.y-k*a.x;
}
}
if(k==)
{
another->k=INF,another->b=(a.x+bb.x)/2.0;
}
else if(k==INF)
{
another->k=,another->b=(a.y+bb.y)/2.0;
}
else
{
another->k=-1.0/k;
struct point temp;
temp.x=(a.x+bb.x)/2.0;
temp.y=(a.y+bb.y)/2.0;
another->b=temp.y-another->k*temp.x;
}
}
};
struct line bi[],ci[]; struct point getnode(line a,line b)
{
struct point res;
res.x=(b.b-a.b)/(a.k-b.k);
res.y=a.k*res.x+a.b;
return res;
} double dist(struct point a,struct point b)
{
double aa=(a.x-b.x)*(a.x-b.x);
double bb=(a.y-b.y)*(a.y-b.y);
aa=sqrt(aa+bb);
return aa;
} double fgcd(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()
{
for(int i=;i<=;i++) cin>>ai[i].x>>ai[i].y;
bi[].updata(ai[],ai[]);
bi[].updata(ai[],ai[]);
bi[].updata(ai[],ai[]);
for(int i=;i<=;i++) ci[i]=*bi[i].another;
struct point o=getnode(ci[],ci[]);
double R=dist(o,ai[]);
double vi[];
vi[]=dist(ai[],ai[]);
vi[]=dist(ai[],ai[]);
vi[]=dist(ai[],ai[]);
sort(vi+,vi+);
double an[];
an[]=2.0*asin(vi[]/(2.0*R));
an[]=2.0*asin(vi[]/(2.0*R));
an[]=2.0*pi-an[]-an[];
sort(an+,an+);
double ans1=fgcd(an[],an[]);
double ans2=fgcd(an[],an[]);
double ans=fgcd(max(ans1,ans2),min(ans1,ans2));
double ans_=(2.0*pi-ans)/2.0;
printf("%.9lf",R*R*sin(ans)*pi/ans);
return ;
}