Codeforces777A Shell Game
来源:互联网 发布:directx 9.0修复软件 编辑:程序博客网 时间:2024/05/21 04:19
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.
42
1
11
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.
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { n%=6; if(m==0) { if(n==1||n==2) printf("1\n"); else if(n==3||n==4) printf("2\n"); else printf("0\n"); } else if(m==1) { if(n==0||n==3) printf("1\n"); else if(n==2||n==5) printf("2\n"); else printf("0\n"); } else { if(n==4||n==5) printf("1\n"); else if(n==0||n==1) printf("2\n"); else printf("0\n"); } } return 0;}
- Codeforces777A Shell Game
- shell game
- Shell Game
- A - Shell Game
- A. Shell Game
- A. Shell Game
- A. Shell Game
- Shell Game CodeForces
- 1550 [CF1000]Shell Game
- 【codeforces 777A】Shell Game
- Codeforces 777A-Shell Game
- CodeForces 777A Shell Game
- Codeforces 777 A Shell Game
- Shell Game (Codeforces-777A)
- A EFI shell app snake game
- Shell Game (类似找骰子游戏)
- 【水模拟】#35 A.Shell Game
- 【CodeForces 777A】Shell Game(模拟)
- 二叉树的后序遍历序列
- 万得——python接口获取A股代码
- HDOJ 1530 Maximum Clique(最大团模板题)
- 教材中没讲的goto语句
- SNMPv3原理-SNMPv3协议框架
- Codeforces777A Shell Game
- uniq指令详解
- NLTK入门学习笔记
- java集合系列12 Map
- 界面平移效果
- thinkphp create方法 用法 详解
- 总结Yii2.0中的Url::to(), Url::toRoute(), Url::current()用法
- index of Practical Software Engineering
- P1028--01背包