代码改变世界

1C - Ancient Berland Circus

2013-10-14 21:50  BrokenJar  阅读(194)  评论(0编辑  收藏  举报
#include <iostream>
#include <iomanip>
#include <cmath>
 
 
const double pi = 3.141592654;
 
inline bool isinteger(double x, int prec)
{
    double decimal = ceil(x)-x < x-floor(x)? ceil(x)-x: x-floor(x);
    return !static_cast<int>(decimal * pow(10, prec - 1));
}
 
int main()
{
    double x1, y1;
    double x2, y2;
    double x3, y3;
     
    std::cin >> x1 >> y1;
    std::cin >> x2 >> y2;
    std::cin >> x3 >> y3;
     
    double mx1 = (x1+x2)*0.5, my1 = (y1+y2)*0.5;
    double mx2 = (x2+x3)*0.5, my2 = (y2+y3)*0.5;
     
    double tx1 = mx1-my1+y1, ty1 = mx1+my1-x1;
    double tx2 = mx1-my1+y2, ty2 = mx1+my1-x2;
    double tx3 = mx2-my2+y2, ty3 = mx2+my2-x2;
    double tx4 = mx2-my2+y3, ty4 = mx2+my2-x3;
 
    double a1 = ty1-ty2, b1 = tx2-tx1, c1 = tx1*ty2-tx2*ty1;
    double a2 = ty3-ty4, b2 = tx4-tx3, c2 = tx3*ty4-tx4*ty3;
     
    double mx = (b1*c2-b2*c1)/(a1*b2-a2*b1);
    double my = (a1*c2-a2*c1)/(a2*b1-a1*b2);
     
    double marg = std::atan2(y2-my, x2-mx);
    double arg1 = std::abs(std::atan2(y1-my, x1-mx) - marg);
    double arg2 = std::abs(std::atan2(y3-my, x3-mx) - marg);
     
    int i;
    double arg;
     
    for(i = 3; i <= 100; ++i)
    {
        arg = pi/i*2;
        if(isinteger(arg1/arg, 6) && isinteger(arg2/arg, 6))
            break;
    }
     
    double l1 = std::pow(x1-mx, 2) + std::pow(y1-my, 2);
    double l2 = std::pow(x2-mx, 2) + std::pow(y2-my, 2);
    double l3 = std::pow(x3-mx, 2) + std::pow(y3-my, 2);
     
    double l = (l1 + l2 + l3) / 3.0;
     
    double area = l * std::sin(arg) * i * 0.5;
     
    std::cout << std::fixed << std::setprecision(6) << area << std::endl;
     
}