A10789 | Shell Game
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from $0$ to $2$ from left to right. Thus the left shell is assigned number $0$ , the middle shell is $1$ and the right shell is $2$ . Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly $n$ movements were made by the operator and the ball was under shell $x$ at the end. Now he wonders, what was the initial position of the ball?
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from $0$ to $2$ from left to right. Thus the left shell is assigned number $0$ , the middle shell is $1$ and the right shell is $2$ . Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly $n$ movements were made by the operator and the ball was under shell $x$ at the end. Now he wonders, what was the initial position of the ball?
输入格式
The first line of the input contains an integer $n$ ( $1<=n<=2·10^{9}$ ) — the number of movements made by the operator.
The second line contains a single integer $x$ ( $0<=x<=2$ ) — the index of the shell where the ball was found after $n$ movements.
The second line contains a single integer $x$ ( $0<=x<=2$ ) — the index of the shell where the ball was found after $n$ movements.
输出格式
Print one integer from $0$ to $2$ — the index of the shell where the ball was initially placed.
输入输出样例
输入 #1
4 2
输出 #1
1
输入 #2
1 1
输出 #2
0
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted