Educational Codeforces Round 87 (Rated for Div. 2) C2. Not So Simple Polygon Embedding(几何)
The statement of this problem is the same as the statement of problem C1. The only difference is that, in problem C1, nn is always even, and in C2, nn is always odd.
You are given a regular polygon with 2⋅n2⋅n vertices (it's convex and has equal sides and equal angles) and all its sides have length 11 . Let's name it as 2n2n -gon.
Your task is to find the square of the minimum size such that you can embed 2n2n -gon in the square. Embedding 2n2n -gon in the square means that you need to place 2n2n -gon in the square in such way that each point which lies inside or on a border of 2n2n -gon should also lie inside or on a border of the square.
You can rotate 2n2n -gon and/or the square.
The first line contains a single integer TT (1≤T≤2001≤T≤200 ) — the number of test cases.
Next TT lines contain descriptions of test cases — one per line. Each line contains single odd integer nn (3≤n≤1993≤n≤199 ). Don't forget you need to embed 2n2n -gon, not an nn -gon.
Print TT real numbers — one per test case. For each test case, print the minimum length of a side of the square 2n2n -gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed 10−610−6 .
3 3 5 199
1.931851653 3.196226611 126.687663595
n是奇数的情况其实本质上就是把n是偶数的情况造出的边与多边形的边平行的正方形转个角度。
类似下图:
其中靠外的正方形表示最终的正方形的大致方向(已经转过了一定角度),靠内的那条线代表真正的最终那个正方形的边。

设a为多边形拆分出的每个小等腰三角形的顶角,l为等腰三角形的腰长,x为转过的角度。
有几何关系:l=0.5/sin(a/2),而多边形几何中心到最终正方形的边的距离d=lcos(x)=cos(x)/(2*sin(a/2))。
这个表达式d对x求导会发现导数小于0,因此是单调递减的。只需要根据x的定义域确定最大值带入即可。
能注意到x的范围是0~a/2,因为角度再大一点就和之前重复了。
但这还不够,继续观察发现角度的范围可以缩小到0~4/a,因为0~a/4和a/4~a/2是对称的。所以直接带入a/4到表达式计算即可。
#include <bits/stdc++.h> #define PI 3.1415926535898 using namespace std; int main() { int t; cin>>t; while(t--) { int n; cin>>n; double ang=360.0/(2*n); ang/=2.0; double ans=0.0; ans=0.5/sin(ang/180.0*PI)*cos(0.5*ang/180.0*PI)*2; printf("%.9lf\n",ans); } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!