'''某公司要从赵,钱,孙,李,周中选派一些人留学,选派必须满足以下条件:
1.若赵去,则钱也去
2.李,周两人中必有一个人去
3.钱,孙两人中去且仅去一人
4.孙,李两人同去或同不去
5.若周去,则赵,钱也同去
问:如何选派'''
for a in range(2):#赵去为a
for b in range(2):#钱去为b
for c in range(2):#孙去为c
for d in range(2):#李去为d
for e in range(2):#周去为e
yi=(not a)or b#第一句话
er=d or e
san=(b and (not c))or(c and (not b))
si=(c and d)or((not c)and(not d))
wu=(not e)or(a and b)
Q=yi and er and san and si and wu#保证这五句话为真
if Q==1:
print("%d,%d,%d,%d,%d"%(a,b,c,d,e))#输出谁去谁不去
离散作业:选派问题代码实现
最新推荐文章于 2024-08-14 23:30:40 发布