CF777A.Shell Game

入门

通过率:0%

时间限制:0.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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?

邦博斯拉夫喜欢从自己房间的窗户向外张望,观看外面的年轻人玩著名的“贝壳游戏”。该游戏由两个人参与:操作员和玩家。操作员取三个外观相同且不透明的贝壳,并将一个小球置于其中某一个贝壳之下。随后,他通过交换某些贝壳对来打乱贝壳顺序,而玩家则需猜测小球当前所在的位置。

邦博斯拉夫注意到,这些年轻人并不太富有创意,因此操作员在奇数次移动(第 1、3、5 … 次等)时总是交换左侧贝壳与中间贝壳,在偶数次移动(第 2、4 … 次等)时总是交换中间贝壳与右侧贝壳。

我们从左至右将贝壳编号为 00 至 22:最左侧贝壳编号为 00,中间贝壳为 11,最右侧贝壳为 22。邦博斯拉夫错过了小球最初被放置到贝壳下的时刻,但他知道操作员恰好进行了 nn 次移动,且最终小球位于编号为 xx 的贝壳之下。现在他想知道:小球最初的起始位置是哪里?

输入格式

The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — 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.

输入的第一行包含一个整数 nn(1 ≤ n ≤ 2⋅1091 ≤ n ≤ 2·10^9)—— 操作员执行的移动次数。

第二行包含一个整数 xx(0 ≤ x ≤ 20 ≤ x ≤ 2)—— 经过 nn 次移动后,球所在贝壳的编号。

输出格式

Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.

输出一个从 0 到 2 的整数——小球最初所在贝壳的索引。

输入输出样例

  • 输入#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. 第一次操作时,操作员交换了左侧壳与中间壳。此时小球位于左侧壳下方。
  2. 第二次操作时,操作员交换了中间壳与右侧壳。小球仍位于左侧壳下方。
  3. 第三次操作时,操作员再次交换了左侧壳与中间壳。小球重新回到中间壳下方。
  4. 最后,操作员交换了中间壳与右侧壳。此时小球位于右侧壳下方。

输入解题思路,AI测评打分。不知道怎么写?

首页