现在的位置: 首页 > 综合 > 正文

UVA12300-Smallest Regular Polygon

2019年11月07日 ⁄ 综合 ⁄ 共 562字 ⁄ 字号 评论关闭

给出两点,求经过这两点的正n边形的最小面积

大白鼠上说要注意精度,我没觉得精度有什么影响,然后就过了

我的做法:

相当于这两点构成的线段是正n边形的最长弦

我的代码:

#include<iostream>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
const double pi=acos(-1.0);
struct dot
{
	int x,y;
	dot(){}
	dot(double a,double b){x=a;y=b;}
};
int main()
{
	int n;
	double c,d,s;
	dot a,b;
	while(cin>>a.x>>a.y>>b.x>>b.y>>n)
	{
		if(a.x+a.y+b.x+b.y+n==0)
			break;
		c=2*pi/n;
		d=pow(a.x-b.x,2)+pow(a.y-b.y,2);
		if(n&1)
			s=d*n*sin(c)/4/(1-cos(pi*(n-1)/n));
		else
			s=d*sin(c)*n/8;
		printf("%.6lf\n",s);
	}
}

抱歉!评论已关闭.