酷代码 AI
菜单
服务商

Python 破解工地楼房可见数量计算难题:每日施工后可见楼数揭秘

以下是使用 Python 解决该问题的代码: ```python # 读取输入 n, m = map(int, input().split()) # 初始化每栋楼的高度为 0 heights = [0] * (n + 1) # 定义一个函数来计算可见的楼房数量 def count_visible(heights): visible = 0 max_slope = 0 for i in range(1, n + 1): if heights[i] > 0: slope = heights[i] / i if slope > max_slope: visible += 1 max_slope = slope return visible # 处理每一天的施工操作 for _ in range(m): xi, yi = map(int, input().split()) # 更新第 xi 栋楼的高度 heights[xi] = yi # 计算并输出当天完工后可见的楼房数量 print(count_visible(heights)) ``` ######[AI问答 | 224点数解答 | 2025-12-13 21:24:53]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]