这题越推越觉得应该用程序写,所以就用python写了一个,为什么用python,因为真的很方便。
先看看理论上是否可行,10道题,每题4个选项,也就是4的10次幂,2的20次幂,也就是20bit,2.5Byte的数据要遍历,这个数量级一般计算机妥妥够用,4Byte以内通常都可以,要是20题就是5Byte就比较吃力了,6Byte就要几周时间了,8Byte就别想了,当然是遍历完,要是在前面就出结果了例外。
下面是python源码:
ask_all = 0;
ask = [0,0,0,0,0,0,0,0,0,0];
while ask_all < 2**20:
for i in range(10):
ask[i] = ((ask_all >> (2*i)) & 0x03);
ask_all = ask_all + 1;
#ASK2
select = [2,3,0,1]
if select[ask[1]] != ask[4]:
continue
#ASK3
flag = 0;
select = [2,5,1,3]
for i in select:
if (ask[i] == ask[select[ask[2]]]) & (i != select[ask[2]]):
flag = 1;
break;
if flag == 1:
continue
#ASK4
select = [[0,4],[1,6],[0,8],[5,9]]
if ask[select[ask[3]][0]] != ask[select[ask[3]][1]]:
continue
#ASK5
select = [7,3,8,6]
if ask[select[ask[4]]] != ask[4]:
continue
#ASK6
select = [[1,3],[0,5],[2,9],[4,8]]
if (ask[select[ask[5]][0]] != ask[7]) | (ask[select[ask[5]][1]] != ask[7]):
continue
#ASK7
select = [2,1,0,3]
count = [ask.count(0),ask.count(1),ask.count(2),ask.count(3)]
if select[ask[6]] != count.index(min(count)):
continue
#ASK8
select = [6,4,1,9]
if (ask[select[ask[7]]] == (ask[0]+1)) | (ask[select[ask[7]]] == (ask[0]-1)):
continue
#ASK9
select = [5,9,1,8]
if ask[0] == ask[5]:
if ask[select[ask[8]]] == ask[4]:
continue
else:
if ask[select[ask[8]]] != ask[4]:
continue
#ASK10
select = [3,2,4,1]
if select[ask[9]] != (max(count) - min(count)):
continue
for i in range(10):
print i+1,
print(‘‘);
for i in ask:
print chr(ord(‘A‘)+i),
结果:
原文地址:https://www.cnblogs.com/dracowangs/p/8495878.html