Codeforces Round #401(Div. 2)A. Shell Game【循环节规律】
来源:互联网 发布:2017年播的网络腐剧 编辑:程序博客网 时间:2024/05/20 00:36
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 is2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactlyn movements were made by the operator and the ball was under shellx 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 aftern 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.
题目大意:
现在一共有三个小盒子,其中有一个盒子中有小球.一共进行了n次操作,操作规律有:
①奇数次操作,交换第一个和中间的盒子。
②偶数次操作,交换第三个和中间的盒子。
现在已知操作了n次之后小球在x号盒子中(0,1,2),问初始的时候小球在哪里;
思路:
1、暴力打表找规律即可。
x==2的时候有规律:2001122200112;
x==1的时候有规律:021021021021;
x==0的时候有规律:112200112200;
2、那么按照规律直接给出答案即可。
Ac代码:
#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;int a[3];int main(){ int n; while(~scanf("%d",&n)) { int x; scanf("%d",&x); if(x==1) { if(n%3==1)printf("0\n"); else if(n%3==2)printf("2\n"); else printf("1\n"); } if(x==0) { if(n%6==1||n%6==2)printf("1\n"); else if(n%6==3||n%6==4)printf("2\n"); else printf("0\n"); } if(x==2) { if(n%6==2||n%6==3)printf("0\n"); else if(n%6==4||n%6==5)printf("1\n"); else printf("2\n"); } }}
- Codeforces Round #401(Div. 2)A. Shell Game【循环节规律】
- Codeforces Round #401 (Div. 2) A. Shell Game(模拟)
- Codeforces Round #401 (Div. 2)A. Shell Game(水题~)
- Codeforces Round #401 (Div. 2) A.shell game
- Codeforces Round #401 (Div. 2) A. Shell Game
- Codeforces Beta Round #35 (Div. 2) / 35A Shell Game(模拟)
- Codeforces Round #277 (Div. 2)---A. Calculating Function (规律)
- Codeforces Round #276 (Div. 2)A. Factory 数学+规律
- Codeforces Round #436 (Div. 2) 864A A. Fair Game
- Codeforces Round #124 (Div. 2) / A. Plate Game
- Codeforces Round #191 (Div. 2)-A. Flipping Game
- Codeforces Round #228 (Div. 2) A. Fox and Number Game
- Codeforces Round #228 (Div. 2)A.Fox and Number Game
- Codeforces Round #228 (Div. 2)A. Fox and Number Game
- Codeforces Round #258 (Div. 2)1A Game With Sticks
- Codeforces Round #191 (Div. 2)---A. Flipping Game
- 【CF】Codeforces Round #124 (Div. 2) 197A Plate Game
- Codeforces Round #124 (Div. 2) A. Plate Game(博弈)
- cs231n-反向传播与神经网络
- 欢迎使用CSDN-markdown编辑器
- Java修饰符总结
- python入门神书:500 lines or less
- python给qq邮箱发送邮件
- Codeforces Round #401(Div. 2)A. Shell Game【循环节规律】
- 安卓使用FastJson解析Json数据并展示到ListView中
- 第一个SpringMVC程序
- http协议--get与post
- maven在项目中的应用
- [Kafka]_1
- web端常见错误以及调试
- 历届试题 九宫重排 (搜索+哈希)
- SpringMVC学习笔记1