zoukankan      html  css  js  c++  java
  • Codeforces Beta Round #1 C. Ancient Berland Circus 计算几何

    C. Ancient Berland Circus

    题目连接:

    http://www.codeforces.com/contest/1/problem/C

    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

    0.000000 0.000000
    1.000000 1.000000
    0.000000 1.000000

    Sample Output

    1.00000000

    Hint

    题意

    给你一个正多边形上的三个点,然后让你输出一个最小的正多边形面积满足这三个点是这个正多边形的顶点。

    题解:

    数学题。

    给你三个点,很容易算出多边形的半径,R = abc / 4S,abc是三边边长,S是三角形面积。

    然后能够构成的最小多边形就是n = pi/gcd(A,B,C)。

    gcd是浮点数。

    然后强行算一波面积就好了。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const double eps = 1e-5;
    const double pi = acos(-1.0);
    struct node
    {
        double x,y;
    }a,b,c;
    double A,B,C;
    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;
    }
    double dis(node p1,node p2)
    {
        return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
    }
    int main()
    {
        cin>>a.x>>a.y;
        cin>>b.x>>b.y;
        cin>>c.x>>c.y;
        A = dis(b,c);
        B = dis(a,c);
        C = dis(a,b);
        double p = (A+B+C)/2.0;
        double S = sqrt(p*(p-A)*(p-B)*(p-C));
        double AA = acos((B*B+C*C-A*A)/(2.0*B*C));
        double BB = acos((C*C+A*A-B*B)/(2.0*A*C));
        double CC = acos((A*A+B*B-C*C)/(2.0*A*B));
        double R = (A*B*C)/(4.0*S);
        double n = (pi/(gcd(AA,gcd(BB,CC))));
        printf("%.12f
    ",n*R*R*sin(2.0*pi/n)/2.0);
    }
  • 相关阅读:
    sql中的并、交、差
    白水的sql需求:每个病人的对应最小诊断类别|partition|
    |转|oracle行转列点评oracle11g sql新功能pivot/unpivot
    oracle wm_concat(column)函数的使用不同公司支付同一客商(行转列)|转|
    记录那些删除的伴我成长的触发器
    PL/SQL Developer使用技巧|F=Forwarding|
    手工创建数据库 ocp课程 wait for
    Oracle数据库监听配置|转|
    最新解决的sql:病人相邻两次看病小于3天
    tns的一些常见错误分析实例 |转|
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5262658.html
Copyright © 2011-2022 走看看