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