1550 [CF1000]Shell Game
来源:互联网 发布:南达科他级战列舰数据 编辑:程序博客网 时间:2024/06/09 23:56
Description
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·10^9) — 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.
Sample Input 1
4
2
Sample Output 1
1
Sample Input 2
1
1
Samppe Output 2
0
Submission
cfa.cpp
#include<iostream>using namespace std;int main(){ int count,final; cin>>count>>final; int mod=count%6; int box[6][3]={{0,1,2},{1,0,2},{2,0,1},{2,1,0},{1,2,0},{0,2,1}}; for(int i=0;i<3;i++){ if(box[mod][i]==final){ cout<<i<<endl; break; } }}
Standard Answer
cfa.cpp
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){ int n, p; scanf("%d%d", &n, &p); n %= 6; int now[3] = {0, 0, 0}; now[p] = 1; while(n) { if(n & 1) swap(now[0], now[1]); else swap(now[1], now[2]);// printf("%d %d %d\n", now[0], now[1], now[2]); n--; } if(now[0]) printf("0\n"); else if(now[1]) printf("1\n"); else printf("2\n"); return 0;}
- 1550 [CF1000]Shell Game
- shell game
- Shell Game
- A - Shell Game
- A. Shell Game
- A. Shell Game
- A. Shell Game
- Codeforces777A Shell Game
- Shell Game CodeForces
- 【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(模拟)
- JDBC连接mysql
- Linux设备驱动调试之printk
- 一个快速实现搜索智能提示的方法
- AVL树之插入与判断
- 2017GDOI
- 1550 [CF1000]Shell Game
- c语言 函数指针
- 各种return的情况下try catch finally的执行顺序
- 云计算概览
- 熵编码(entropy encoder)
- Revit开发之管段
- db_lmdb.hpp:15] Check failed: mdb_status
- spring中beanfactory和applicationcontext创建bean的区别
- mybatis中#{}和${}的区别与用法