uva 12300 - Smallest Regular Polygon


題意:2つの点AとBを与えて、この2つの点を含む面積の最小の正n(既知)の辺形を求める.
#include<iostream>
#include<iomanip>
#include<cmath>
#define pi 2.0*asin(1.0)
#define sqr(a) ((a)*(a))

using namespace std;

int main()
{
    int n;
    double x1,x2,y1,y2,d,thy,s;
    while(cin>>x1>>y1>>x2>>y2>>n && x1+x2+y1+y2+n)
    {
        d=sqrt(sqr(x1-x2)+sqr(y1-y2));
        thy=pi-2*pi/n;
        if(n%2)
            s=n*sqr(d*cos((thy+pi)/4))*tan(thy/2);
        else
            s=n*sqr(d/2)*sin(thy)/2;
        cout<<fixed<<setprecision(6)<<s<<endl;
    }
    return 0;
}