CodeForces1345C1. Simple Polygon Embedding

给一个偶数 n n ,代表一个正 2 n 2*n 边形,求最小外接正方形的边长。

n n 为偶数时,代表 2 n 2*n 一定可以被4整除,那么正方形一定可以和正 2 n 2*n 边形的4条边完美贴合。这就是最小的正方形。因为一旦进行旋转,正方形的面积就会增大,那么边长也会增大。

img

计算正方形边长:

2 n 2*n 边形内角用公式来算: α = ( 2 n 2 ) π 2 n = ( n 1 ) π n \alpha=\frac{(2*n-2)*\pi}{2*n}=\frac{(n-1)*\pi}{n}

计算 x x 长度: x = 1 2 t a n ( α 2 ) x=\frac{1}{2}*tan(\frac{\alpha}{2})

正方形边长: a n s = 2 x = t a n ( ( n 1 ) π 2 n ) ans=2*x=tan(\frac{(n-1)*\pi}{2*n})

#include <bits/stdc++.h>
#define pb push_back 
#define fir first
#define sec second
#define ms(a,b) memset(a,b,sizeof(a)) 
#define INF 0x3f3f3f3f
#define sp system("pause")
using namespace std;
typedef long long ll;
typedef double db;
const int N=1e4+5;
const int mod=10007;
const db pi=acos(-1.0);
int main()
{
    int t;
    double n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        printf("%lf\n",tan((n-1)*pi/n/2));
    }
    #ifndef ONLINE_JUDGE
    sp;
    #endif
}

猜你喜欢

转载自blog.csdn.net/Luowaterbi/article/details/106220112