题意:给定两个点A和B,求包含这两个点的面积最小的正 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; }