AcWing 116. 飞行员兄弟-Python
原题链接
简单
作者:
生日快乐
,
2021-02-20 19:02:25
,
所有人可见
,
阅读 327
'''
枚举
16 ** 4
'''
from itertools import product
import copy
import sys
mat = [[0] * 4 for i in range(4)]
key = list(product(range(0, 2), repeat = 4))
#变成全1矩阵
for i in range(4):
tmp = input()
tmp = tmp.replace('+', '0')
tmp = tmp.replace('-', '1')
mat[i][:] = list(map(int, tmp))
def change(x, y):
global box
for i in range(4):
box[x][i] ^= 1
for j in range(4):
box[j][y] ^= 1
box[x][y] ^= 1
def do(row, idx):
for i in range(4):
if key[idx][i] == 1:
change(row, i)
for i in range(16):
for j in range(16):
for k in range(16):
for q in range(16):
box = copy.deepcopy(mat)
do(0, i)
do(1, j)
do(2, k)
do(3, q)
s = sum(box[0]) + sum(box[1]) + sum(box[2]) + sum(box[3])
if s == 16:
print(sum(key[i])+sum(key[j])+sum(key[k])+sum(key[q]))
for h in range(4):
if key[i][h]: print(1, h + 1)
for h in range(4):
if key[j][h]: print(2, h + 1)
for h in range(4):
if key[k][h]: print(3, h + 1)
for h in range(4):
if key[q][h]: print(4, h + 1)
sys.exit()