2018年刑侦科推理试题 python实现

 

这题越推越觉得应该用程序写,所以就用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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值