1C. Ancient Berland Circus

time limit: per test 2 seconds
memory limit :per test 64 megabytes
input:standard input
output:standard output
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.

In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a special pillar, and the rope strung between the pillars marked the arena edges.

Recently the scientists from Berland have discovered the remains of the ancient circus arena. They found only three pillars, the others were destroyed by the time.

You are given the coordinates of these three pillars. Find out what is the smallest area that the arena could have.

Input
The input file consists of three lines, each of them contains a pair of numbers –– coordinates of the pillar. Any coordinate doesn’t exceed 1000 by absolute value, and is given with at most six digits after decimal point.

Output
Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It’s guaranteed that the number of angles in the optimal polygon is not larger than 100.

Examples
input
0.000000 0.000000
1.000000 1.000000
0.000000 1.000000
output
1.00000000

此题为几何问题,大致思路为求得三条边对应的三个圆心角,并且求三个圆心角的最大公约数,利用此圆心角作为正多边形每条边所对应的圆心角,从而通过计算出每个三角形面积最后组合出整个正多边形的面积。
这里必须用2*PI - angle_1 - angle_2,而不可以用余弦定理求出第三个角,求arccos时精度有很大的问题,这一点需要注意。

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

#define epi 1e-2
#define PI acos(-1)
struct point{
    double x,y;
};
double getLength(point &a,point &b){
    return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
double getAngle(double a,double R){
    double number = 1-pow(a,2)/(2*pow(R,2));
    return acos(number);
}
double gcd(double a,double b){
    if(fabs(b)<epi)
        return a;
    if(fabs(a)<epi)
        return b;
    return gcd(b,fmod(a,b));
}



int main(int argc, char *argv[])
{ 

    point pa,pb,pc;
    scanf("%lf %lf",&pa.x,&pa.y);
    scanf("%lf %lf",&pb.x,&pb.y);
    scanf("%lf %lf",&pc.x,&pc.y);

    double ab =  getLength(pa,pb);
    double ac =  getLength(pa,pc);
    double bc =  getLength(pb,pc);

    double p = (ab + ac + bc)/2;
    double S = sqrt(p*(p-ab)*(p-ac)*(p-bc));
    double R = ab*ac*bc/(4*S);

    double angle_1 = getAngle(ab,R);
    double angle_2 = getAngle(ac,R);
    //double angle_3 = getAngle(bc,R); //?????
    double angle_3 = 2*PI - angle_1 - angle_2; 
    double central_angle = gcd(angle_1,gcd(angle_2,angle_3));

    double N = 2*PI/central_angle; //double......
    double S_poly = 1.0f/2*pow(R,2)*sin(central_angle)*N;
    printf("%.6lf",S_poly);

    return 0;
}

转载于:https://www.cnblogs.com/GoFly/p/5751071.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值