题解 | #报数游戏#

报数游戏

http://www.nowcoder.com/practice/b29badef4e4545bca349e407b378bb88

# 输入m,n
n = int(input())
m = int(input())

# 创建n_list列表,记录每个人所在的位置
n_list = list(range(1,n+1))
# 创建out_list列表,用于记录退出的人所在位置
out_list = [] 
while len(n_list):
    # 将1 2 3 分别从n_list中移除,并插入到最后
    for i in range(3):
        n_list.append(n_list.pop(0))
    # 移除3,插入到out_list
    out_list.append(n_list.pop(-1)) 
    
# 查看牛牛所在的m位置在退出列表中的哪个位置
print(out_list.index(m)+1)
    
全部评论

相关推荐

09-29 15:34
已编辑
北京航空航天大学 C++
做个有文化的流氓:结果是好的,过程不重要,而且你的offer太多了
软开人,秋招你打算投哪些...
点赞 评论 收藏
分享
评论
7
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务