博客
关于我
poj1113——求凸包的周长
阅读量:656 次
发布时间:2019-03-15

本文共 882 字,大约阅读时间需要 2 分钟。

为了找到围绕王国城堡的最小可能长度的围墙,我们需要将每个顶点向外扩展一定距离。具体步骤如下:

  • 计算原多边形的周长:遍历每个顶点,计算相邻顶点之间的欧氏距离之和,即为原多边形的周长。

  • 计算扩展后的总周长:每个顶点扩展后的圆弧长度为πL,总共有N个顶点,因此总周长等于原周长加上N×πL。

  • 四舍五入结果:将最终结果四舍五入到最近的整数。

  • 以下是实现代码:

    import mathn, L = map(int, input().split())points = [tuple(map(int, input().split())) for _ in range(n)]# Calculate the perimeter of the original polygonperimeter = 0.0for i in range(n):    x1, y1 = points[i]    x2, y2 = points[(i+1) % n]    dx = x2 - x1    dy = y2 - y1    dist = math.hypot(dx, dy)    perimeter += dist# Total perimeter after expansiontotal = perimeter + n * math.pi * L# Round to the nearest integerresult = round(total)print(result)

    步骤解释:

  • 读取输入:首先读取顶点数量N和最小允许距离L,然后读取每个顶点的坐标。

  • 计算原周长:遍历每个顶点,计算其与下一个顶点的欧氏距离,并累加得到原多边形的周长。

  • 计算扩展后的周长:每个顶点扩展成一个圆,半径为L,每个圆贡献一个半圆的周长πL,总共有N个半圆,因此总扩展长度为N×πL。

  • 总周长:将原多边形的周长与扩展后的长度相加,得到总周长。

  • 四舍五入结果:将总周长四舍五入到最近的整数,确保结果精确到8英寸(1英尺=12英寸)。

  • 这个方法确保了围墙的最小长度,同时满足每个顶点到围墙的距离至少为L。

    转载地址:http://wwfmz.baihongyu.com/

    你可能感兴趣的文章
    python关于sorted排序函数详细解析 附实战代码(全)
    查看>>
    python3.8调用m文件,调用matlab
    查看>>
    python3.9新特性_Python 3.9 新特性速览
    查看>>
    Python3.x:遍历select下拉框获取value值
    查看>>
    python360百科_11月编程排行榜:Python超过Java成第二
    查看>>
    Python关于Paginator分页函数详细解析 附实战代码
    查看>>
    python3、ipython3、setup-tools、pip等环境搭建详细总结
    查看>>
    python3下使用cv2.imwrite存储带有中文路径图片或者绝对路径图片
    查看>>
    python3与django中@property详解
    查看>>
    python3中如何表示无穷大
    查看>>
    Python3中提示:no module named 'wxpy'
    查看>>
    python3中选择文件对话框的格式打开和保存图片
    查看>>
    python3为什么print永远都是地址_Python3 print 函数用法总结
    查看>>
    Python3之uuid模块
    查看>>
    Python3之写入Excel文档(xlsxwriter)
    查看>>
    Python3之打印操作打印流重定向(下)
    查看>>
    python3判断字典、列表、元组为空以及字典是否存在某个key的方法
    查看>>
    Python3利用pymysql操作 MySQL
    查看>>
    python3处理json文件中含有中文dumps的应用
    查看>>
    Python3子进程输出
    查看>>