用了一个自认为很简单的方法写的,测试用例打印出来看起来没问题。
#coding=utf-8
import sys
if __name__ == "__main__":
# 读取第一行的n
T = int(sys.stdin.readline().strip())
list_answers =[]
for i in range(T):
# T 组数据
# 读取每一行
N = int(sys.stdin.readline().strip())
count_up = 0
count_down = 0
count_left = 0
count_right = 0
for j in range(N):
line = sys.stdin.readline().strip()
direction, if_succeed = line.split()
if if_succeed == '1' and direction == '0':
count_up = count_up+1
if if_succeed == '1' and direction == '1':
count_down = count_down+1
if if_succeed == '1' and direction == '2':
count_left = count_left+1
if if_succeed == '1' and direction == '3':
count_right = count_right+1
print(abs(count_up-count_down)+abs(count_left-count_right))
全部评论
(2) 回帖