CF 777A

来源:互联网 发布:长春网络专业人才市场 编辑:程序博客网 时间:2024/06/16 03:43
A. Shell Game
time limit per test
0.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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?

Input

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.

Output

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

Examples
input
42
output
1
input
11
output
0
Note

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.
/*  水题。  题意:给你三个帽子,然后在帽子下面放一个球,然后盖住,不停的移动帽子,最后让你猜那个球在哪个帽子下面。  这种游戏大家应该都很熟悉。  这题比较无脑,因为他移动的方法很固定,左边和中间的帽子交换 右边和中间的帽子交换 左边和中间的帽子交换 不停的循环。  输入n 、 m 分别代表 交换了n次 m为球最后那个帽子下面的编号 叫你输出球最初在哪个帽子下面。  状态数就三个情况,球在左边帽子下面 中间帽子下面 右边帽子下面。  在草稿纸上面分析下即可。*/#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <string>#include <cstdlib>using namespace std;int main(void){    long long int n;    scanf("%I64d",&n);    n%=6;    int m;    scanf("%d",&m);    if(n==1&&m==0||n==2&&m==0||n==3&&m==1||n==4&&m==2||n==5&&m==2||n==0&&m==1) printf("1\n");    else if(n==1&&m==2||n==2&&m==1||n==3&&m==0||n==4&&m==0||n==5&&m==1||n==0&&m==2) printf("2\n");    else printf("0\n");    return 0;}/*解法二:相对简洁很多。原理都是一样的。*/#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <string>#include <cstdlib>using namespace std;int a[6][3]={0,1,2,1,0,2,1,2,0,2,1,0,2,0,1,0,2,1};int main(){int m,n;cin>>m>>n;m%=6;cout<<a[m][n]<<endl;}



0 0
原创粉丝点击