Codeforces Round #401 (Div. 2)A. Shell Game(水题~)

题目:

A. 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
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.
思路:

找规律,打表,我写的有点长。。尴尬

代码1(我的):

#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define N 200+20
#define M 100000+20
#define inf 0x3f3f3f3f
using namespace std;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    if(n==1)
    {
        if(m==1)
            printf("0\n");
        else if(m==0)
            printf("1\n");
        else if(m==2)
            printf("2\n");
    }
    else if(n>1)
    {
        int t=n%6;
        if(t==0)
        {
            if(m==0)printf("0\n");
            if(m==1)printf("1\n");
            if(m==2)printf("2\n");
        }
        if(t==1)
        {
            if(m==0)printf("1\n");
            if(m==1)printf("0\n");
            if(m==2)printf("2\n");
        }
        if(t==2)
        {
            if(m==0)printf("1\n");
            if(m==1)printf("2\n");
            if(m==2)printf("0\n");
        }
        if(t==3)
        {
            if(m==0)printf("2\n");
            if(m==1)printf("1\n");
            if(m==2)printf("0\n");
        }
        if(t==4)
        {
            if(m==0)printf("2\n");
            if(m==1)printf("0\n");
            if(m==2)printf("1\n");
        }
        if(t==5)
        {
            if(m==0)printf("0\n");
            if(m==1)printf("2\n");
            if(m==2)printf("1\n");
        }
    }
    return 0;
}
代码2(比较精简的代码):

#include<stdio.h>
int main()
{
    int t[6][3]= {0,1,2,1,0,2,1,2,0,2,1,0,2,0,1,0,2,1};
    int n,x;
    scanf("%d%d",&n,&x);
    n=n%6;
    printf("%d\n",t[n][x]);
}
PS:思路很重要啊,虽然题目很水,但是我用这么多代码还是比较羞耻的。。。 委屈


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值