zoukankan      html  css  js  c++  java
  • Shell Game (模拟)

    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
    1
    1
    Output
    0

    Note

    In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.

    1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
    2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
    3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
    4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <string>
    #include <vector>
    #include <map>
    #include <set>
    #include <list>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <cstdio>
    #include <cmath>
    #include <iomanip>
    #define ull unsigned long long
    #define ll long long
    #define pb push_back
    #define all(vc) vc.begin() , vc.end()
    #define rep(i,start,end) for(int i=start;i<=end;i++)
    #define per(i,end,start) for(int i=end;i>=start;i--)
    #define tle ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #define lc now<<1
    #define rc now<<1|1
    ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    using namespace std;
    const int mod = 998244353;
    const int mxn = 2e5 +7;
    ll _,n,m,t,k,u,v,ans,cnt,ok,lim,len,tmp;
    ll  a[mxn] ,inv[mxn],lazy[mxn],id[mxn];
    string str , s1 ,s2;
    bool vis[mxn];
    int dir[6][3] = {{0,1,2},{1,0,2},{1,2,0},{2,1,0},{2,0,1},{0,2,1}};
    /// dir 代表每次交换之后从左到右外壳的编号
    int main()
    {
        while(cin>>n>>m)
            cout<<dir[n%6][m]<<endl;
    /// 先左边和中间交换,然后中间和右边交换
    /// m 是最后停止的位置,也就是问 m 位置的外壳编号
    }
    所遇皆星河
  • 相关阅读:
    电脑常用快捷键
    k8s node 系统参数调整
    docker 制作镜像并上传
    php服务部署安装
    安装 Kuboard v2
    keepalive配置
    elasticsearch的segment详解
    grafana模板
    jenkins启动
    kubernetes 中文文档
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/12868546.html
Copyright © 2011-2022 走看看