Python-CCF:20191202 回收站选址

题目

在这里插入图片描述在这里插入图片描述在这里插入图片描述

用时

读题5分钟+写代码40分钟
写代码用时太长了,不是很满意
主要是有一处应该用局部变量的地方脑子一抽用了全局变量
导致在这debug了十几分钟

满分代码

if __name__ == "__main__":
    point_num = int(input())
    all_coordinates = []

    score_place = [0, 0, 0, 0, 0]
    # 01234每个得分各有几处选址

    for pn in range(point_num):
        all_coordinates.append(list(map(int, input().split(' '))))
    for cd in all_coordinates:
        cd_up = [cd[0], cd[1] + 1]
        cd_down = [cd[0], cd[1] - 1]
        cd_left = [cd[0] - 1, cd[1]]
        cd_right = [cd[0] + 1, cd[1]]
        if cd_up in all_coordinates and cd_down in all_coordinates and cd_left in all_coordinates and cd_right in all_coordinates:
            # 上下左右都有则可选址
            cd_l_u = [cd[0] - 1, cd[1] + 1]
            cd_r_u = [cd[0] + 1, cd[1] + 1]
            cd_l_d = [cd[0] - 1, cd[1] - 1]
            cd_r_d = [cd[0] + 1, cd[1] - 1]
            score_point = []
            score_point.append(cd_l_u)
            score_point.append(cd_r_u)
            score_point.append(cd_l_d)
            score_point.append(cd_r_d)
            cd_score = 0
            for sp in score_point:
                if sp in all_coordinates:
                    cd_score += 1
            score_place[cd_score] += 1
    for sp in score_place:
        print(sp)

总结

很简单的,无需多言
主要是score_point一开始定义成了全局变量,导致所有的可选址的点共用一个大的计分点组
也就是说每个点的计分点组本来应该是4个对角
但是用全局变量后连前面可选址点的计分点组也算进去了
这个错误就耗了不少时间
太蠢了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值