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

    你可能感兴趣的文章
    Orcale表被锁
    查看>>
    svn访问报错500
    查看>>
    Orderer节点启动报错解决方案:Not bootstrapping because of 3 existing channels
    查看>>
    org.apache.ibatis.exceptions.PersistenceException:
    查看>>
    org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
    查看>>
    org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
    查看>>
    org.apache.poi.hssf.util.Region
    查看>>
    org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
    查看>>
    org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
    查看>>
    org.hibernate.HibernateException: Unable to get the default Bean Validation factory
    查看>>
    org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
    查看>>
    SQL-CLR 类型映射 (LINQ to SQL)
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>
    org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
    查看>>
    org.tinygroup.serviceprocessor-服务处理器
    查看>>
    org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
    查看>>
    org/hibernate/validator/internal/engine
    查看>>
    Orleans框架------基于Actor模型生成分布式Id
    查看>>
    SQL-36 创建一个actor_name表,将actor表中的所有first_name以及last_name导入改表。
    查看>>