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个对角
但是用全局变量后连前面可选址点的计分点组也算进去了
这个错误就耗了不少时间
太蠢了

发布了61 篇原创文章 · 获赞 11 · 访问量 4864

猜你喜欢

转载自blog.csdn.net/weixin_43249758/article/details/104104890