• codeforces1c给出三点求面积


    题意:有一个正n边形的斗兽场,现存有3根柱子,柱子位于正n边形的任意3个节点上。求出正n边形的最小面积。

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <stdlib.h>
     4 #include <math.h>//采用三角函数大部分使用弧度
     5 #include <utility>
     6 #include <algorithm>
     7 using namespace std;
     8 const double eps=1e-5;
     9 const double pi=acos(-1.0);
    10 pair<double,double> p1;
    11 pair<double,double> p2;
    12 pair<double,double> p3;
    13 /*
    14  三角形外接圆半径:r=abc/4*s;
    15  面积:s=(a*b*sinC)/2=abc/4r;sinC=c/2r;
    16  最小k边形边数=2*pi/gcd(2A,gcd(2B,2C)),gcd(2A,gcd(2B,2C))表示能够符合正n边形的最大角度
    17  园周角=园心角的一半  A,B,C为三角形对应得园周角
    18  正n边形面积:n(r^2/2*sin(最大角度))
    19 */
    20 double area(double a,double b,double c)
    21 {
    22     double p=(a+b+c)/2;
    23     return sqrt(p*(p-a)*(p-b)*(p-c));
    24 }
    25 double length(pair<double,double> &a,pair<double,double> &b)
    26 {
    27     return sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
    28 }
    29 double gcd(double a,double b)
    30 {
    31     while(fabs(a-b)>eps&&a>0&&b>0)
    32     {
    33         if(a-b>eps)
    34         {
    35             a-=b;
    36         }
    37         else if(b-a>eps)
    38         {
    39             b-=a;
    40         }
    41     }
    42     return a;
    43 }
    44 int main()
    45 {
    46     double s,a,r,n,angelp1,angelp2,angelp3,len1,len2,len3;
    47     while(scanf("%lf%lf%lf%lf%lf%lf",&p1.first,&p1.second,&p2.first,&p2.second,&p3.first,&p3.second)!=EOF)
    48     {
    49         len1=length(p1,p2);
    50         len2=length(p1,p3);
    51         len3=length(p2,p3);
    52         a=(len1+len2+len3)/2;
    53         s=sqrt(a*(a-len1)*(a-len2)*(a-len3));
    54         r=len1*len2*len3/(4*s);
    55         angelp1=(len1*len1+len2*len2-len3*len3)/(2*len1*len2);
    56         angelp2=(len1*len1+len3*len3-len2*len2)/(2*len1*len3);
    57         angelp3=(len2*len2+len3*len3-len1*len1)/(2*len2*len3);
    58         n=pi/gcd(acos(angelp1),gcd(acos(angelp2),acos(angelp3)));
    59         double ans=n/2*r*r*sin(2*pi/n);
    60         printf("%lf
    ",ans);
    61     }
    62     return 0;
    63 }
    View Code
  • 相关阅读:
    深入理解 IE haslayout
    electron的应用
    自动化批量录入Web系统
    Flask + Vue的一个示例
    如何从git仓库里下载单个文件夹
    Django项目设置首页
    简单更改Django Admin登录页面
    Flask web项目使用.flaskenv文件
    Flask 里url_for的使用
    使用Flask-migrate迁移数据库
  • 原文地址:https://www.cnblogs.com/linxhsy/p/4598800.html
Copyright © 2020-2023  润新知