codeforces--Ancient Berland Circus(三点确定最小多边形)

Ancient Berland Circus

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d
& %I64u

Submit Status

Appoint description: 
System Crawler  (2015-01-06)

Description

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 Input

Input

0.000000 0.000000
1.000000 1.000000
0.000000 1.000000

Output

1.00000000

题目大意:给出三个点,求出以这三个点为定点的最小正多边形。

求最小正多边形,边数越多,面积越大,所以要是求得的多边形的边尽量的小。

由三个点组成的三角形,可以确定一个外接圆,那么正多边形的所有的定点应该都在圆上,求出三边对应的圆心角,找出圆心角的最大公约数,也就得到了多边形的最小的边数。

防止钝角的情况,边长最长的对应的圆心角 = 2*PI - 其他两个圆心角。

#include <cstdio>
#include <cstring>
#include <math.h>
#include <algorithm>
using namespace std ;
#define PI acos(-1)
#define eqs 0.01
double gcd(double a,double b)
{
    return a < eqs ? b : gcd(fmod(b,a),a);
}
int main()
{
    double x1 , y1 , x2 , y2 , x3 , y3 ;
    double a , b , c , p , s , r , k ;
    double A , B , C ;
    scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3) ;
    a = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) ;
    b = sqrt( (x2-x3)*(x2-x3) + (y2-y3)*(y2-y3) ) ;
    c = sqrt( (x1-x3)*(x1-x3) + (y1-y3)*(y1-y3) ) ;
    p = ( a + b + c ) / 2.0 ;
    s = sqrt( p * (p-a) * (p-b) * (p-c) ) ;
    r = a * b * c / ( 4 * s ) ;
    if( a > c )
    {
        k = a ; a = c ; c = k ;
    }
    if( b > c )
    {
        k = b ; b = c ; c = k ;
    }
    A = 2 * asin(a/(2*r)) ;
    B = 2 * asin(b/(2*r)) ;
    C = 2 * PI - A - B ;
    //printf("%lf %lf %lf\n", A, B, C) ;
    p = gcd(A,B);
    p = gcd(p,C) ;
    //printf("%lf %lf\n", r, p) ;
    printf("%.6lf\n", (PI*r*r*sin(p))/p ) ;
    return 0;
}
时间: 2024-10-29 04:52:51

codeforces--Ancient Berland Circus(三点确定最小多边形)的相关文章

Codeforces Beta Round #1 C. Ancient Berland Circus

果然Java还是不靠谱啊,一个NaN把我整了半天~~ 题目大意: 有一个正多边形,给出任意三个顶点的坐标,求这个正多边形的最小面积. 解题思路: 首先要知道这三个顶点组成的三角形的外接圆一定是这个正多边形的外接圆. 用过计算出三角形的三边长,可以计算出三角型面积,进而推出外接圆半径. 可以得到三个圆心角,找出最大公约数,那就是最大角度. 就可以计算出多边形面积了~~ 下面是代码: import java.text.DecimalFormat; import java.util.Scanner;

CodeForce-1C Ancient Berland Circus

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 o

CodeForces 1C Ancient Berland Circus

题意:给定三个点,求包含三点的正多边形最小面积: 思路:求圆心角最大公约数,多边形面积=每个小三角形面积和: #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<stack> #include<string> #include<map> #include<iostream> using namespace

Ancient Berland Circus CodeForces - 1C

题意:给定一个正多边形的三个顶点,求这个正多边形的最小面积. 思路:首先,边数越小面积越小,所以只要确定出包含这三个顶点的边数最小的正多边形即可.这个三角形和正多边形外接同一个圆.所以先求出外接圆的半径,再求出三个圆心角,易得这个多边形的边所对应的圆心角可被这三个圆心角整除,所以三个圆心角的gcd就是多边形边所对的圆心角,然后2π除一下就得到是几边形,之后就可计算面积了 海伦公式: p=(a+b+c)/2,S=√p(p-a)(p-b)(p-c)(a,b,c为三角形的三边,S为三角形面积) 求外接

codeforces Round #1 C题 Ancient Berland Circus (计算几何)

这题的思路很好想,分成以下4步: 1:求外切园半径 2:求三个圆心角 3:求三个圆心角的最大公约数 4:最大公约数就是最大的正多边形内角,求面积即可. 但是每一步都不会求啊....sad...当想到第3步的时候甚至觉得应该用别的方法来求..要换方法..几何太渣了. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algo

CodeForces 567B Berland National Library

Description Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room. Today was the pilot launch of an automated

机器学习方法:回归(三):最小角回归Least Angle Regression(LARS),forward stagewise selection

希望与志同道合的朋友一起交流,我刚刚设立了了一个技术交流QQ群:433250724,欢迎对算法.技术.应用感兴趣的同学加入. 前面两篇回归(一)(二)复习了线性回归,以及L1与L2正则--lasso和ridge regression.特别描述了lasso的稀疏性是如何产生的.在本篇中介绍一下和lasso可以产生差不多效果的两种feature selection的方法,forward stagewise selection和最小角回归least angle regression(LARS).尤其是

Codeforces 618D Hamiltonian Spanning Tree(树的最小路径覆盖)

题意:给出一张完全图,所有的边的边权都是 y,现在给出图的一个生成树,将生成树上的边的边权改为 x,求一条距离最短的哈密顿路径. 先考虑x>=y的情况,那么应该尽量不走生成树上的边,如果生成树上有一个点的度数是n-1,那么必然需要走一条生成树上的边,此时答案为x+y*(n-2). 否则可以不走生成树上的边,则答案为y*(n-1). 再考虑x<y的情况,那么应该尽量走生成树上的边,由于树上没有环,于是我们每一次需要走树的一条路,然后需要从非生成树上的边跳到树的另一个点上去, 显然跳的越少越好,于

CodeForces 567B Berland National Library(模拟)(简单)

B. Berland National Library time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Berland National Library has recently been built in the capital of Berland. In addition, in the library you can t