#Man number 0 - N #Woman number 0 - N # TT number 0 - N def dispalyTT (): global N, TT_inside, TT_outside #Show who 's virus is included in the inside and outside of each TT print ( " \t- -------Poison status of current TT------- " ) for index in range(N): print ( " \t TT %d number " %(index),end= '' ) print ( " in: " ,end= '' ) for gender, id in TT_inside[index]: if gender == ' male': print('%d号男'%id,end=',') else: print('%d号女'%id,end=',') print("外:",end='') for gender, id in TT_outside[index]: if gender == ' male': print ( ' %d male ' %id,end= ' , ' ) else : print ( ' %d female ' %id,end= ' , ' ) print ( '' ) print ( ' ****** **************************************************** **** ' ) def infect_test(gender, id, virus): global Infected #Infected test function, if the contacting TT contains other XX of the same gender, mark Infected as True # virus stores the contacting whose virus is contained in the TT for _gender, _id in virus: #A homosexual in the virus, but someone else's, GG if _gender == gender and _id != id: Infected = True print('Infected : %s %d using these TTs with virus : '%(gender,id), virus) def make_love_test(male, female, tt_number): global N, TT_inside, TT_outside #Do a ML and judge whether there will be an infection #From the inside to the outside, the connected TT viruses infect each other for enum in range(tt_number): #Currently processing the first TT from the inside to the outside this_index = (male + enum) % N if enum == 0: #If it is the innermost TT, it is necessary to judge whether the inner side of this TT includes other men's viruses infect_test( ' male ' , male, TT_inside[this_index]) TT_inside[this_index].add(( ' male ' ,male)) else : #For other cases, the inside of the current TT should be attached to the outside virus of the previous TT last_index = (this_index - 1 ) % N TT_inside[this_index].update(TT_outside[last_index]) if enum == tt_number - 1 : #If it is the outermost TT, it is necessary to judge whether the outer side of this TT includes other women's viruses infect_test ( ' female ' , female, TT_outside[this_index]) TT_outside[this_index].add(( ' female ' , female)) else : #For other cases, the outside of the current TT should be attached to the inside virus of the next TT next_index = (this_index + 1 ) % N TT_outside[this_index].update(TT_inside[next_index]) if __name__ == '__main__': # NTo shameless but sympathetic men and women N = 4 #Mark if there is an infection Infected = False #Store the viruses of men and women contained in each TT TT_inside = [set() for _ in range(N)] #Store which men and women's viruses are contained outside each TT TT_outside = [set() for _ in range(N)] #You guys don't worry, come one by one for male in range(N): #Use TT from more to less for tt_number in range(N, 0, -1 ): #Calculate which little pitiful was ruthlessly trampled on (guarantee that each woman is only touched by one TT) female = (male + tt_number - 1) % N #Output which pair is currently trading, and the TT they use (from the inside to the outside) print ( ' %d male x %d female, TT number from the inside to the outside: ' %(male,female) ,[(male + offset)%N for offset in range(tt_number)]) #Come on, be happy make_love_test(male, female, tt_number) # Oh~ WTF ~ infected! if Infected == True: exit(-1) #Display whose virus is included on the inside and outside of TT at this time # dispalyTT () #hee hee, happy ending print ( ' without any infection ' )