• 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

    题意:给出三个点的坐标,求出由这三个顶点构成的最小多边形的面积。

    题解:计算几何。这道题目有点思维难度,我们需要分析一下。

    我们知道,三个不共线的点可以唯一确定一个圆。而一个正多边形在圆里就容易确定,因此我们可以考虑先确定圆的半径R。

    根据海伦公式,我们可以先算三角形的面积。S=sqrt(p(p-a)(p-b)(p-c)),其中p=(a+b+c)/2;

    当然,三角形面积公式还可以用S=0.5absinC来算。

    根据正弦定理,a/sinA=b/sinB=c/sinC=2R,因此,可以得到sinC=c/2R。

    故S=0.25abc/R,得到R=abc/4S。

    再根据余弦定理cos(c)=(a2+b2-c2)/2ab,可以算出三角形三边对应的圆心角,根据公式变形,得cosθ=(r2+r2-a2)/2r2,我们可以算出2条边对应的圆心角,第三个圆心角用2π-θ[1]-θ[2]求得,这样可以防止钝角三角形产生的bug。

    我们可以思考一下,钝角三角形对应一个外接圆,那么钝角所对应的圆心角将是其他两个锐角所对应圆心角之和,加起来不是2π,所以用上述方法可以防止这种情况的出现。

    怎样可以使多边形面积取得最小值呢?我们可以想到,在同一个圆中,正多边形边数越少,面积越小。

    现在求得了三个圆心角,我们只需要将此三个角取最大公约数σ,就是我们要构造的最小面积的多边形的一边所对应的圆心角。因此,多边形边数为n=2π/σ。

    我们可以根据三角形面积公式S=0.5absinC算这个多边形中单个三角形的面积(a=r,b=r,sinC=sinσ),然后乘以n就可以了。
     1 #include<bits/stdc++.h>
     2 #define pi acos(-1.0)
     3 #define eps 1e-4
     4 using namespace std;
     5 double p,s,r,Max,ans,x[3],y[3],len[3],angle[3];
     6 double get_dis(int a,int b)
     7 {
     8     return sqrt((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]));
     9 }
    10 double fgcd(double a,double b)
    11 {
    12     return fabs(a)<eps?b:(fabs(b)<eps?a:fgcd(b,fmod(a,b)));
    13 }
    14 int main()
    15 {
    16     for (int i=0;i<3;++i)
    17     scanf("%lf%lf",&x[i],&y[i]);
    18     for (int i=0;i<3;++i)
    19     len[i]=get_dis(i,(i+1)%3);
    20     p=(len[0]+len[1]+len[2])/2;
    21     s=sqrt(p*(p-len[0])*(p-len[1])*(p-len[2]));
    22     r=(len[0]*len[1]*len[2])/(4*s);
    23     for (int i=0;i<2;++i)
    24     angle[i]=acos(1-(len[i]*len[i])/(2*r*r));
    25     angle[2]=2*pi-angle[0]-angle[1];
    26     Max=fgcd(angle[0],fgcd(angle[1],angle[2]));
    27     ans=r*r*sin(Max)*0.5*(2*pi/Max);
    28     printf("%0.6lf
    ",ans);
    29     return 0;
    30 }
    View Code
  • 相关阅读:
    Dropdown 下拉菜单
    Breadcrumb 面包屑
    Tabs 标签页
    NavMenu 导航菜单
    Notification 通知
    MessageBox 弹框
    Message 消息提示
    Loading 加载
    Alert 警告
    Badge 标记
  • 原文地址:https://www.cnblogs.com/zk1431043937/p/7593289.html
Copyright © 2020-2023  润新知