前言
暂1
202009-3点亮数字人生
前两个测试点(Q=1):最后print的有错误
def cal_one(func, num_lst):
if func == "NOT":
flag = not num_lst[0]
elif func == "AND":
flag = not 0 in num_lst
elif func == "OR":
flag = 1 in num_lst
elif func == "XOR":
flag = num_lst[0]
for num in num_lst[1:]:
flag = 1 if flag != num else 0
elif func == "NAND":
flag = 0 in num_lst
else:
flag = not 1 in num_lst
if type(flag) == int:
return flag
return 1 if flag == True else 0
def cal_all(I_lst, cell_lst):
tmp_O_lst = []
for cell in cell_lst:
func = cell[0]
num_lst = [I_lst[int(i[1:])-1] if i[0] == "I" else tmp_O_lst[int(i[1:])-1] for i in cell[2:]]
tmp_O_lst.append(cal_one(func, num_lst))
return tmp_O_lst
Q = int(input())
for q in range(Q):
M,N = list(map(int, input().split()))
cell_lst = []
O_lst = []
for n in range(N):
cell_lst.append(input().split())
S = int(input())
for s in range(S):
I_lst = list(map(int, input().split()))
O_lst.append(cal_all(I_lst, cell_lst))
for s in range(S):
input_lst = list(map(int,input().split()))
cell_num = input_lst[0]
for idx,cell_idx in enumerate(input_lst[1:]):
if idx!= cell_num -1:
print(O_lst[s][cell_idx-1], end=" ")
else:
# 这里写错了
if s != S-1:
print(O_lst[s][cell_idx-1])
else:
print(O_lst[s][cell_idx-1], end="")
前5个测试点:没有考虑环
def cal_one(func, num_lst):
if func == "NOT":
flag = not num_lst[0]
elif func == "AND":
flag = not 0 in num_lst
elif func == "OR":
flag = 1 in num_lst
elif func == "XOR":
flag = num_lst[0]
for num in num_lst[1:]:
flag = 1 if flag != num else 0
elif func == "NAND":
flag = 0 in num_lst
else:
flag = not 1 in num_lst
if type(flag) == int:
return flag
return 1 if flag == True else 0
def cal_all(I_lst, cell_lst):
tmp_O_lst = []
for cell in cell_lst:
func = cell[0]
num_lst = [I_lst[int(i[1:])-1] if i[0] == "I" else tmp_O_lst[int(i[1:])-1] for i in cell[2:]]
tmp_O_lst.append(cal_one(func, num_lst))
return tmp_O_lst
Q = int(input())
for q in range(Q):
M,N = list(map(int, input().split()))
cell_lst = []
O_lst = []
for n in range(N):
cell_lst.append(input().split())
S = int(input())
for s in range(S):
I_lst = list(map(int, input().split()))
O_lst.append(cal_all(I_lst, cell_lst))
for s in range(S):
input_lst = list(map(int,input().split()))
cell_num = input_lst[0]
for idx,cell_idx in enumerate(input_lst[1:]):
if idx!= cell_num -1:
print(O_lst[s][cell_idx-1], end=" ")
else:
print(O_lst[s][cell_idx-1])
全部测试点
def cal_one(func, num_lst):
if func == "NOT":
flag = not num_lst[0]
elif func == "AND":
flag = not 0 in num_lst
elif func == "OR":
flag = 1 in num_lst
elif func == "XOR":
flag = num_lst[0]
for num in num_lst[1:]:
flag = 1 if flag != num else 0
elif func == "NAND":
flag = 0 in num_lst
else:
flag = not 1 in num_lst
if type(flag) == int:
return flag
return 1 if flag == True else 0
def cal_all(I_lst, cell_lst):
tmp_O_lst = []
for cell in cell_lst:
func = cell[0]
num_lst = []
for i in cell[2:]:
if i[0] == "I":
num_lst.append(I_lst[int(i[1:])-1])
else:
# circle
if int(i[1:]) > len(tmp_O_lst):
return False
else:
num_lst.append(tmp_O_lst[int(i[1:])-1])
int(i[1:]) - 1
# num_lst = [I_lst[int(i[1:])-1] if i[0] == "I" else tmp_O_lst[int(i[1:])-1] for i in cell[2:]]
tmp_O_lst.append(cal_one(func, num_lst))
return tmp_O_lst
Q = int(input())
for q in range(Q):
M,N = list(map(int, input().split()))
cell_lst = []
O_lst = []
for n in range(N):
cell_lst.append(input().split())
S = int(input())
for s in range(S):
I_lst = list(map(int, input().split()))
result = cal_all(I_lst, cell_lst)
O_lst.append(cal_all(I_lst, cell_lst))
for s in range(S):
input_lst = list(map(int,input().split()))
if O_lst[s] != False:
cell_num = input_lst[0]
for idx,cell_idx in enumerate(input_lst[1:]):
if idx!= cell_num -1:
print(O_lst[s][cell_idx-1], end=" ")
else:
print(O_lst[s][cell_idx-1])
else:
continue
# print LOOP
if O_lst[0] == False:
print("LOOP")