思路题
来源:互联网 发布:医院网络部管理制度 编辑:程序博客网 时间:2024/04/30 14:42
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?
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.
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
4
2
1
1
1
0
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
- During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
- During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
- During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
- Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
{
int n,m;
while(~scanf("%d%d",&m,&n))
{
m=m%6;
if(n==0)
{
if(m==1||m==2)
printf("1\n");
else if(m==3||m==4)
printf("2\n");
else
printf("0\n");
}
if(n==1)
{
if(m==3||m==0)
printf("1\n");
else if(m==2||m==5)
printf("2\n");
else
printf("0\n");
}
if(n==2)
{
if(m==4||m==5)
printf("1\n");
else if(m==1||m==0)
printf("2\n");
else
printf("0\n");
}
}
}
- 思路题
- 思路题
- 思路题
- 思路题
- 作文185题思路
- hduDP题(思路)
- 练思路的题
- ZOJ 3327(思路题)
- HDU 4970 思路题
- HDU 5301 思路题
- 周赛 5 【思路题】
- POJ 1904 思路题
- nyoj 1809 思路题
- 思路!
- 思路
- 思路
- 思路
- 思路
- 1000. 函数求值
- 人见人爱A-B
- Redis-字典
- x&(x-1)=?
- JAVA NIO技术
- 思路题
- bzoj 2844 albus就是要第一个出场
- 配对交易(搬砖)
- ubuntu下hive2.1.1部署安装
- gcc [options]详情
- linux系统安装jdk并配置环境变量
- Java类 属性 构造方法 方法 对象。+一个模拟银行存取款^_^
- tf.train.ExponentialMovingAverage解析
- android 生成arr包或 jar包