题解 | #报数游戏#

报数游戏

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)
    
全部评论

相关推荐

08-27 12:02
已编辑
南京外国语学校 网络安全
再来一遍:实则劝各位不要all in华子,不要相信华为hr
点赞 评论 收藏
分享
昨天 17:42
酷酷的喜马拉雅山:你为什么发我的offer列表?
点赞 评论 收藏
分享
评论
7
收藏
分享

创作者周榜

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