zoukankan      html  css  js  c++  java
  • codeforces 1C (非原创)

    C. 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 - 其他两个圆心角。

    r=a*b*c/(4*s)求出外接圆的面积,然后通过正弦定理求出三角形三个边各自的圆心角,然后利用求gcd函数求出A,B,C最大公约数。

    由于三角形每条边所对应的圆心角都是正多边形圆心角的整数倍,故n=2*pi/gcd(A,B,C),然后正多边形的面积便是n个相同的三角形的面积了,其中每个三角形面积为r*r/2*sin(p),正多边形面积即可求出.

    即:   S =  2*PI/p * 1/2*r*r*sin(p) =  PI*r*r*sin(p)/p

    附代码:

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cmath>
     4 #include <algorithm>
     5 using namespace std ;
     6 const double  PI = acos(-1.0);
     7 const double  eqs = 0.01;
     8 double gcd(double a,double b)
     9 {
    10     return a < eqs ? b : gcd(fmod(b,a),a);
    11 }
    12 int main()
    13 {
    14     double x1 , y1 , x2 , y2 , x3 , y3 ;
    15     double a , b , c , p , s , r , k ;
    16     double A , B , C ;
    17     scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3) ;
    18     a = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) ;
    19     b = sqrt( (x2-x3)*(x2-x3) + (y2-y3)*(y2-y3) ) ;
    20     c = sqrt( (x1-x3)*(x1-x3) + (y1-y3)*(y1-y3) ) ;
    21     p = ( a + b + c ) / 2.0 ;
    22     s = sqrt( p * (p-a) * (p-b) * (p-c) ) ;
    23     r = a * b * c / ( 4 * s ) ;
    24     if( a > c )
    25     {
    26         k = a ; a = c ; c = k ;
    27     }
    28     if( b > c )
    29     {
    30         k = b ; b = c ; c = k ;
    31     }
    32     A = 2 * asin(a/(2*r)) ;   //正弦定理 
    33     B = 2 * asin(b/(2*r)) ;
    34     C = 2 * PI - A - B ;
    35     //printf("%lf %lf %lf
    ", A, B, C) ;
    36     p = gcd(A,B);
    37     p = gcd(p,C) ;
    38     //printf("%lf %lf
    ", r, p) ;
    39     printf("%.6lf
    ", PI*r*r*sin(p)/p ) ;//1/2*a*b*sinc 三角形已知两边一角的面积公式 
    40     return 0;
    41 }
    View Code

    参考博客:http://blog.csdn.net/winddreams/article/details/42532203

  • 相关阅读:
    视频质量诊断之详解
    Leetcode 22.生成括号对数
    leetcode 19.删除链表的第n个节点
    Leetcode 11.盛最多水的容器
    Leetcode 6.Z字形变换
    Leetcode 4.两个排序数组的中位数
    Leetcode 3.无重复字符的最长子串
    Leetcode 1.两数之和
    RNN and Language modeling in TensorFlow
    Tensorflow word2vec+manage experiments
  • 原文地址:https://www.cnblogs.com/zmin/p/7622407.html
Copyright © 2011-2022 走看看