博客
关于我
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/

    你可能感兴趣的文章
    POJ 1765 November Rain
    查看>>
    poj 1860 Currency Exchange
    查看>>
    POJ 1961 Period
    查看>>
    POJ 2019 Cornfields (二维RMQ)
    查看>>
    poj 2057 The Lost House 贪心思想在动态规划上的应用
    查看>>
    poj 2057 树形DP,数学期望
    查看>>
    poj 2112 最优挤奶方案
    查看>>
    Qt编写自定义控件12-进度仪表盘
    查看>>
    poj 2186 Popular Cows :求能被有多少点是能被所有点到达的点 tarjan O(E)
    查看>>
    POJ 2186:Popular Cows Tarjan模板题
    查看>>
    POJ 2229 Sumsets(递推,找规律)
    查看>>
    poj 2236
    查看>>
    POJ 2243 Knight Moves
    查看>>
    POJ 2262 Goldbach's Conjecture
    查看>>
    POJ 2362 Square DFS
    查看>>
    Qt笔记——解决添加Qt Designer Form Class时“allocation of incomplete type Ui::”
    查看>>
    poj 2386 Lake Counting(BFS解法)
    查看>>
    poj 2387 最短路模板题
    查看>>
    POJ 2391 多源多汇拆点最大流 +flody+二分答案
    查看>>
    POJ 2403
    查看>>