Simple Polygon Embedding CodeForces - 1354C1(计算几何)

2024-02-01 13:58

本文主要是介绍Simple Polygon Embedding CodeForces - 1354C1(计算几何),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, n is always even, and in C2, n is always odd.

You are given a regular polygon with 2⋅n vertices (it’s convex and has equal sides and equal angles) and all its sides have length 1. Let’s name it as 2n-gon.

Your task is to find the square of the minimum size such that you can embed 2n-gon in the square. Embedding 2n-gon in the square means that you need to place 2n-gon in the square in such way that each point which lies inside or on a border of 2n-gon should also lie inside or on a border of the square.

You can rotate 2n-gon and/or the square.

Input
The first line contains a single integer T (1≤T≤200) — the number of test cases.

Next T lines contain descriptions of test cases — one per line. Each line contains single even integer n (2≤n≤200). Don’t forget you need to embed 2n-gon, not an n-gon.

Output
Print T real numbers — one per test case. For each test case, print the minimum length of a side of the square 2n-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn’t exceed 10−6.

Example
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
思路:比第二道题目简单的不是一点半点。主要用到了余弦定理。
代码如下:

#include<bits/stdc++.h>
#define ll long long
#define PI acos(-1.0)
using namespace std;int n;int main()
{int t;scanf("%d",&t);while(t--){scanf("%d",&n);int m=n;n*=2;double z=1.0/(2.0-2.0*cos(PI/(m*1.0)));double y=z+z-2.0*z*cos(((m-2)*1.0/n)*PI);double x=sqrt(y/2.0);x=2.0*x+1.0;printf("%.9lf\n",x);}return 0;
}

努力加油a啊,(o)/~

这篇关于Simple Polygon Embedding CodeForces - 1354C1(计算几何)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/667499

相关文章

计算绕原点旋转某角度后的点的坐标

问题: A点(x, y)按顺时针旋转 theta 角度后点的坐标为A1点(x1,y1)  ,求x1 y1坐标用(x,y)和 theta 来表示 方法一: 设 OA 向量和x轴的角度为 alpha , 那么顺时针转过 theta后 ,OA1 向量和x轴的角度为 (alpha - theta) 。 使用圆的参数方程来表示点坐标。A的坐标可以表示为: \[\left\{ {\begin{ar

【云计算 复习】第1节 云计算概述和 GFS + chunk

一、云计算概述 1.云计算的商业模式 (1)软件即服务(SaaS) 有些景区给游客提供烧烤场地,游客需要自己挖坑或者砌烧烤台,然后买肉、串串、烧烤。 (2)平台即服务(PaaS) 有些景区给游客提供烧烤场地,同时搭建好烧烤台,游客只需要自己带食材和调料、串串、烧烤。 (3)基础设施即服务(IaaS) 有些景区给游客提供烧烤场地,同时搭建好烧烤台,还有专门的厨师来烧烤,用户不需要关心前面的所有

POLYGON Horror Carnival - Low Poly 3D Art by Synty

465 个独特的预设模型 一个正在运行的摩天轮和旋转木马 包括10个示例脚本,让嘉年华栩栩如生 ◼ 描述◼ 欢迎来到恐怖嘉年华。这个地方曾经有诱人的音乐,现在却有着令人不安的旋律,暗示着其中令人不安的惊喜。 这场险恶的盛会的真正核心在于演示场景。它使用3D低多边形资源构建,具有来自不祥的狂欢帐篷、摊位、摩天轮、旋转木马等游戏开发资源。它是疯狂人物与毫无戒心的寻求刺激者玩捉迷藏游戏的完美狩猎场。

什么是dB?dBm、dBc、dBi、dBd怎么计算,有什么区别?

什么是dB?dBm、dBc、dBi、dBd怎么计算,有什么区别? 引言 在电子工程、通信和音频领域,dB(分贝)是一个常见的术语。许多人刚接触时可能会感到困惑,因为它不仅仅是一个简单的单位,还有多种不同的形式,如dBm、dBc、dBi和dBd。这篇文章将详细解释这些概念,并介绍如何计算它们,帮助初学者更好地理解和应用。 什么是dB? dB,即分贝,是一种表示两个数值比值的对数单位。分贝的基

几何内核开发-实现自己的NURBS曲线生成API

我去年有一篇帖子,介绍了NURBS曲线生成与显示的实现代码。 https://blog.csdn.net/stonewu/article/details/133387469?spm=1001.2014.3001.5501文章浏览阅读323次,点赞4次,收藏2次。搞3D几何内核算法研究,必须学习NURBS样条曲线曲面。看《非均匀有理B样条 第2版》这本书,学习起来,事半功倍。在《插件化算法研究平台

Codeforces 158B

很久没有刷题了,刚刚有小学弟问了这道题,AC之后贴上来吧。水~~~ #include <cstdio>#include <cmath>int main() {int n;while(scanf("%d", &n) != EOF) {int a = 0, b = 0, c = 0, d = 0;int arr[100001];for (int i = 0; i < n; ++

Codeforces April Fools Day Contest 2014(附官方题解)

Codeforces2014年愚人节的坑题。。。但还是感觉挺好玩的。。。 A. The Great Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Two teams mee

Codeforces April Fools Day Contest 2013

2013年愚人节的坑题。。。 A. Mysterious strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Input The input contains a sin

AI大模型企业应用实战(14)-langchain的Embedding

1 安装依赖 ! pip install --upgrade langchain! pip install --upgrade openai==0.27.8! pip install -U langchain-openai ! pip show openai! pip show langchain! pip show langchain-openai 2 Embed_document

php字符串计算汉字、中英文数字个数

$str = '123abcDEF测试的事发地点';$length = strlen(preg_replace('/[\x00-\x7F]/', '', $str));$arr['en'] = strlen( $str) - $length; //(非中文)$arr['cn'] = intval($length / 3); // 编码GBK,除以2 (中文)print_r($