python刷题之路

xiaoxiao2021-07-27  122

python刷题之路

题目:两个乒乓球队进行比赛,各出三人。甲队为 a,b,c 三人,乙队为 x,y,z 三人。已 抽签决定比赛名单。 有人向队员打听比赛的名单。 a 说他不和 x 比,c 说他不和 x,z 比, 请编程序找出三队赛手的名单

import random from pprint import pprint import pandas as pd A=[‘a’,‘b’,‘c’] B=[‘x’,‘y’,‘z’] rules=[(‘a’,‘x’),(‘c’,‘x’),(‘c’,‘z’)] final=[] a=0 def make_possible_list(): possibles = [] a=0 while 1: A_n = random.choice(A) B_n = random.choice(B) cur=(A_n,B_n) if cur !=a: if cur not in possibles: if (cur!=rules[0]) and (cur!=rules[1] and cur!=rules[-1]): possibles.append(cur) print(cur) z=[j[0] for j in possibles] e=[j[1] for j in possibles] if ((‘a’ in z )and (‘b’ in z )and (‘c’ in z) )and ((‘x’ in e) and(‘y’ in e)and(‘z’ in e)): return possibles # continue a = cur else: print(‘keep searching’) continue

###[(‘a’, ‘z’), (‘b’, ‘x’), (‘a’, ‘y’), (‘b’, ‘z’), (‘b’, ‘y’), (‘c’, ‘y’)] final=[] while 1: li=make_possible_list() final.append(li) if len(final)==8000: break pprint(pd.Series(final).map(lambda x:str(x)).unique())

转载请注明原文地址: https://www.6miu.com/read-4823384.html

最新回复(0)