酷代码 AI
菜单

小南有一套可爱的玩具小人, 它们各有不同的职业。 有一天, 这些玩具小人把小南的眼镜藏了起来。 小南发现玩具小人们围成了一个圈,它们有的面朝圈内,有的面朝圈外。如下图: 这时 singer 告诉小南一个谜題: “眼镜藏在我左数第 个玩具小人的右数第 个玩具小人的左数第 个玩具小人那里。 ” 小南发现, 这个谜题中玩具小人的朝向非常关键, 因为朝内和朝外的玩具小人的左右方向是相反的: 面朝圈内的玩具小人, 它的左边是顺时针方向, 右边是逆时针方向; 而面向圈外的玩具小人, 它的左边是逆时针方向, 右边是顺时针方向。 小南一边艰难地辨认着玩具小人, 一边数着: singer 朝内, 左数第 个是 archer。 archer 朝外,右数第 个是 thinker 。 thinker 朝外, 左数第 个是 writer。 所以眼镜藏在 writer 这里! 虽然成功找回了眼镜, 但小南并没有放心。 如果下次有更多的玩具小人藏他的眼镜, 或是谜题的长度更长, 他可能就无法找到眼镜了。所以小南希望你写程序帮他解决类似的谜题。 这样的谜題具体可以描述为:

```python n, m = map(int, input().split()) # 存储每个玩具小人的朝向和职业 people = [] for _ in range(n): direction, occupation = input().split() people.append((int(direction), occupation)) # 处理指令 current_index = 0 for _ in range(m): left_or_right, step = map(int, input().split()) current_direction = people[current_index][0] # 调整左右方向 if (current_direction == 0 and left_or_right == 0) or (current_direction == 1 and left_or_right == 1): current_index = (current_index + step) % n else: current_index = (current_index - step) % n print(people[current_index][1]) ``` [2026-01-24 12:57:27 | AI问答 | 184点数解答]

服务商
相关提问
发财导航,免费问AI
实用工具查看更多