Educational Codeforces Round 87 (Rated for Div. 2) C1+C2(几何图形/找规律)

本文探讨了正2n边形最小外接正方形边长的计算方法,区分了n为偶数和奇数两种情况,并提供了详细的数学推导过程,包括关键的三角函数应用和代码实现。

C1传送门

C2传送门


给出一个正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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值