美文网首页
Codeforces 1354C1 - Simple Polyg

Codeforces 1354C1 - Simple Polyg

作者: 费城的二鹏 | 来源:发表于2020-06-18 19:37 被阅读0次

日常一道算法题。

翻译

简单多边形嵌入

给你整数 n,构造一个有 2*n 个边的等边凸多边形,边长为 1。

你的任务是找到一个正方形,可以讲上面的多边形嵌入正方形内。找到最小的正方形,输出边长。

输入格式

输入整数 T 表示测试用例组数。

接下来每个测试用例输入一个整数 n。

输出格式

输出最小的边长。

分析

公式是:

1 / math.tan(math.pi * 2 / (n * 4))

代码(Python3)

# https://codeforces.com/problemset/problem/1354/C1
 
import sys
import os
import heapq
import math
 
try:
    path = "./file/input.txt"
    if os.path.exists(path):
        sys.stdin = open(path, 'r')
    # sys.stdout = open(r"./file/output.txt", 'w')
except:
    pass
 
t = int(input())
 
def printd(value):
    # print(value)
    pass
 
def case():
    n = int(input())
    result = 1 / math.tan(math.pi * 2 / (n * 4))
    print(result)

for _ in range(t):
    case()

更多代码尽在 https://github.com/Tconan99/Codeforces

by 费城的二鹏 2020.06.17 长春

相关文章

网友评论

      本文标题:Codeforces 1354C1 - Simple Polyg

      本文链接:https://www.haomeiwen.com/subject/uzhexktx.html