zoukankan      html  css  js  c++  java
  • Ancient Berland Circus CodeForces

    题意:给定一个正多边形的三个顶点,求这个正多边形的最小面积。

    思路:首先,边数越小面积越小,所以只要确定出包含这三个顶点的边数最小的正多边形即可。这个三角形和正多边形外接同一个圆。所以先求出外接圆的半径,再求出三个圆心角,易得这个多边形的边所对应的圆心角可被这三个圆心角整除,所以三个圆心角的gcd就是多边形边所对的圆心角,然后2π除一下就得到是几边形,之后就可计算面积了

    海伦公式: p=(a+b+c)/2,S=√p(p-a)(p-b)(p-c)(a,b,c为三角形的三边,S为三角形面积) 

    求外接圆半径r=a*b*c/4S 

    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    #include<stack>
    #include<cstdlib>
    #include<queue>
    #include<set>
    #include<string.h>
    #include<vector>
    #include<deque>
    #include<map>
    using namespace std;
    #define INF 0x3f3f3f3f
    #define eps 1e-4
    #define bug printf("*********
    ")
    #define debug(x) cout<<#x"=["<<x<<"]" <<endl
    typedef long long LL;
    typedef long long ll;
    const int MAXN = 1e6 + 5;
    const int mod = 998244353;
    
    struct node{
        double x,y;
    };
    double len(node a,node b) {
        double tmp = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
        return tmp;
    }
    double gcd(double x,double y) {
        while(fabs(x) > eps && fabs(y) > eps) {
            if(x > y)
                x -= floor(x / y) * y;
            else
                y -= floor(y / x) * x;
        }
        return x + y;
    }
    int main()
    {
        node a,b,c;
        cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y;
        double lena = len(a,b);
        double lenb = len(b,c);
        double lenc = len(a,c);
    
        double p = (lena + lenb + lenc) / 2.0;
        double S = sqrt(p * (p - lena) * (p - lenb) * (p - lenc));
        double R = lena * lenb * lenc / (4.0 * S);
        double A = acos((lenb * lenb + lenc * lenc - lena * lena) / (2 * lenb * lenc));
        double B = acos((lena * lena + lenc * lenc - lenb * lenb) / (2 * lena * lenc));
        double C = acos((lena * lena + lenb * lenb - lenc * lenc) / (2 * lena * lenb));
        double PI = acos(-1.0);
        double n = PI / gcd(gcd(A,B),C);
        double ans = n / 2 * R * R * sin(2 * PI / n);
        printf("%.10f
    ",ans);
    }
  • 相关阅读:
    (OK) CORE nodes access Internet—虚拟节点访问互联网—commands
    Open VSwitch—离开VMware的SDN之父Martin Casado是神马大神
    (OK-half) Fedora23——Docker——CORE—testing
    【codeforces 752B】Santa Claus and Keyboard Check
    【codeforces 752C】Santa Claus and Robot
    【codeforces 752E】Santa Claus and Tangerines
    【codeforces 548E】Mike and Foam
    【codeforces 752D】Santa Claus and a Palindrome
    【codeforces 752F】Santa Clauses and a Soccer Championship
    【codeforces 546A】Soldier and Bananas
  • 原文地址:https://www.cnblogs.com/smallhester/p/11361273.html
Copyright © 2011-2022 走看看