问题相关描述
有15个基督徒和15个非基督徒在海上遇险,为了能让一部分人活下来不得不将其中15个人扔到海里面去,有个人想了个办法就是大家围成一个圈,由某个人开始从1报数,报到9的人就扔到海里面,他后面的人接着从1开始报数,报到9的人继续扔到海里面,直到扔掉15个人。由于上帝的保佑,15个基督徒都幸免于难,问这些人最开始是怎么站的,哪些位置是基督徒哪些位置是非基督徒。(用1代表基督徒,0代表非基督徒)
预期输出结果:
101010101010101010101010101010
def main():
# 请在此处添加代码 #
# *************begin************#
person = [1] * 30
down_person = 0
index = 0
flag = 1
while down_person != 15:
if (flag == 9) and (person[index] != 0):
flag = 0
person[index] = 0
down_person += 1
index += 1
if index == 30:
index = 0
if person[index] == 1:
flag += 1
for i in person:
print(i,end = '')
# **************end*************#
if __name__ == '__main__':
main()