[Codeforces 系列] Codeforces 1C. Ancient Berland Circus

1C. Ancient Berland Circus

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

题意

现代的马戏团都有一共13米直径的圆形竞技场,在古代则不是,古代的竞技场都是由等边多边形构成的,在多边形的每个顶点上都有根柱子,然后由绳子连接相邻的两个柱子形成竞技场,现在由考古学家发现一个竞技场,但是由于时间摧毁了大部分柱子,只有3根柱子的位置可以辨别,问如何根据三个顶点(柱子)的位置,求该竞技场最小的面积。

输入

三个顶点的坐标,绝对值不超过1000,小数点后面6位数。

输出

输出该面积,至少精确到小数点后6位,同时保证多边形的边数不会超过100

分析

这是Codeforces系列第一道稍有难度的题,重点考察几何数学知识,同时有两种解法。

解法一

  1. 由等边多边形的性质可得该多边形的所有顶点必定在其外接圆上, 而每条边对应的圆心角必然相等
  2. 贪心的想,边数越少,得到的正多边形面积必然越小,边数越多,正多边形的面积就趋向于外接圆的面积,这个问题就转换成了求最小边数。
  3. 结合1和2,得出边对应的圆心角越大,则边数越少,我们不妨求已知三个点形成的圆心角的最大公约数,因为公约数是将其等分的必要条件,而最大就保证了边数最小。
  4. 只要得到边所对应的圆心角,我们就可以计算该正多边形的面积了,由海伦公式和三角形面积公式可知, r = a b c 4 ∗ p ( p − a ) ( p − b ) ( p − c ) r=\frac{abc}{4*\sqrt{p(p-a)(p-b)(p-c)}} r=4p(pa)(pb)(pc) abc 其中 p = a + b + c 2 p=\frac{a+b+c}{2} p=2a+b+c,a,b,c, 则为三边长,可由坐标计算得到。
  5. 由正多边形面积计算公式即可得到该正多边形面积 S = 1 2 n r 2 s i n φ S=\frac{1}{2}nr^2sinφ S=21nr2sinφ 其中 n为边数(圆心为360度,除于等边对应圆心角即可得边数), r为外接圆半径,φ为一边所对应的圆心角。

解法二

未完待续

代码

未完待续

// placeholder

你可能感兴趣的:(算法,C++,codeforces)