CCF-CSP第三题汇总(python)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了CCF-CSP第三题汇总(python),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3662字,纯文字阅读大概需要6分钟。
内容图文
![CCF-CSP第三题汇总(python)](/upload/InfoBanner/zyjiaocheng/618/3009dd4bb2df4c3e8074c15456fc5b1d.jpg)
前言
暂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")
内容总结
以上是互联网集市为您收集整理的CCF-CSP第三题汇总(python)全部内容,希望文章能够帮你解决CCF-CSP第三题汇总(python)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】