给出一个正2n边形,求出其最小外接正方形的边长
当n为偶数时
不难发现正多边形刚好有四条边和正方形的四条边重合,观察发现该正多边形的边长刚好为内接圆的直径

当n为奇数时
第一眼可能以为和偶数的差不多,但是那样显然正方形的面积会变大,实际上稍微旋转可以得到这样的面积最小的正方形

参考了是yinjun呀的博客,博主用GIF图解释了旋转过程中为什么这样的面积最小,然后由对称性我们得到:

设正多边形每条边对应的圆心角均为
θ
θ
θ:
正多边形的外接圆半径为 r = 0.5 / s i n ( θ / 2 ) r=0.5/sin(θ/2) r=0.5/sin(θ/2)
设正方形边长为 d d d,那么有:
c o s ( θ / 4 ) = ( d / 2 ) / r cos(θ/4)=(d/2)/r cos(θ/4)=(d/2)/r
最后得出 d = c o s ( θ / 4 ) / s i n ( θ / 2 ) d=cos(θ/4)/sin(θ/2) d=cos(θ/4)/sin(θ/2)
PS:比赛时花半天功夫找规律,因为画出来的图不规范,导致找错了规律。实际上这样的图形借助于WORD或者PPT都能很轻松很直观地展示出来,以后一定注意!
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int Mod=1e9+7;
const int maxn=2e5+10;
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
/*//C1
double o=pi/n;
double ans=1.0/tan(o/2);
printf("%.9f\n",ans);*/
double o=pi/n;
double ans=1/sin(o/2)*cos(o/4);
printf("%.9f\n",ans);
}
return 0;
}
本文探讨了正2n边形最小外接正方形边长的计算方法,区分了n为偶数和奇数两种情况,并提供了详细的数学推导过程,包括关键的三角函数应用和代码实现。
759

被折叠的 条评论
为什么被折叠?



