求面积最小的多边形

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.

Sample test(s)
input
0.000000 0.000000
1.000000 1.000000
0.000000 1.000000
output
1.00000000

已知某正n边形的其中三个顶点,求使这三个点是正多边形顶点的最小的多边形的面积。

1.根据海伦公式求出三角形面积

2.根据正弦定理求出三角形外接圆半径

3.根据比例关系求出正多边形最小的外角

4.输出答案

注意求第三个角的时候用2 * pi减去另两个角,否则误差过大


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <string>

using namespace std;

const double pi = acos(-1.0);
const double eps = 1e-2;

struct Node
{
    double x, y;
}node[4];

double area(double a, double b, double c)
{
    double p = (a + b + c) / 2.0;

    return sqrt(p * (p - a) * (p - b) * (p - c));
}

double mul(double x)
{
    return x * x;
}

double dist(int i, int j)
{
    return sqrt(mul(node[i].x - node[j].x) + mul(node[i].y - node[j].y));
}

bool feq(double x)
{
    return fabs(x) < eps ? true : false;
}
double fgcd(double a, double b)
{
    if (feq(b))
    {
        return a;
    }
    if (feq(a))
    {
        return b;
    }
    return fgcd(b, fmod(a, b));
}

void input()
{
    int t = 0;

    while (scanf("%lf %lf", &node[t].x, &node[t].y) != EOF)
    {
        t++;
        if (t == 3)
        {
            double a = dist(0, 1), b = dist(0, 2), c = dist(1, 2);
            double r = a * b * c / (4 * area(a, b, c));		//求外接圆半径

            double p = asin(a / 2 / r) * 2, q = asin(b / 2 / r) * 2;
            double m = 2 * pi - p - q;				//求三边对应的圆心角

            double flag = fgcd(q, m);				//求最小角度
            double temp = fgcd(p, flag);

            printf("%.6lf\n", pi * 2 / temp * 0.5 * r * r * sin(temp));
        }
    }
}
int main()
{
    input();
    return 0;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值