Codeforces 777A-Shell Game
2017-02-25 21:20
375 查看
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
output
input
output
Note
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.
题意:有三个不透明容器,其中一个容器装有小球,容器编号为0 1 2 初始也是按照0 1 2排列,并始终按照left与mid交换,然后mid与right交换的顺序操作。输入N代表操作次数,X代表最终小球所在的容器位置,找出初始时小球所在的位置。
解题思路:模拟前几次操作会发现六次一循环,手动打表出前六次的结果,然后n%6即可
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
4 2
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.
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.
题意:有三个不透明容器,其中一个容器装有小球,容器编号为0 1 2 初始也是按照0 1 2排列,并始终按照left与mid交换,然后mid与right交换的顺序操作。输入N代表操作次数,X代表最终小球所在的容器位置,找出初始时小球所在的位置。
解题思路:模拟前几次操作会发现六次一循环,手动打表出前六次的结果,然后n%6即可
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <vector> #include <set> #include <stack> #include <map> #include <climits> using namespace std; #define LL long long int main() { int a[6][3]= {{0,1,2},{1,0,2},{1,2,0},{2,1,0},{2,0,1},{0,2,1}}; int n,x; while(~scanf("%d %d",&n,&x)) { printf("%d\n",a[n%6][x]); } return 0; }
相关文章推荐
- CodeForces 777A Shell Game
- Shell Game (Codeforces-777A)
- 【CodeForces 777A】Shell Game(模拟)
- Codeforces 777A Shell Game
- cf 777A - A. Shell Game (水)
- 【构造】 Codeforces 468A 24 Game
- codeforces 768 E Game of Stones(博弈)
- Codeforces 468A 24 Game(构造)
- codeforces 468A. 24 Game 解题报告
- Codeforces - 777A. Shell Game 思维或者模拟
- Codeforces Round #401 (Div. 2) A. Shell Game(模拟)
- Codeforces Round #401(Div. 2)A. Shell Game【循环节规律】
- codeforces 777A
- CodeForces 834 C. The Meaningless Game
- codeforces-546D-Soldier and Number Game【思维】(求质因子个数)
- Codeforces 280C Game on Tree 树形期望dp
- Codeforces 327A-Flipping Game(暴力枚举)
- codeforces 2016-2017 NTUWFTSC J Zero Game
- Codeforces Beta Round #35 (Div. 2) / 35A Shell Game(模拟)
- Codeforces 365(Div.2)A.Mishka and Game【水题】