Codeforces Round #401 (Div. 2) A. Shell Game cyclic section rule __codeforces#401div.

Source: Internet
Author: User

A. Shell Game time limit/test 0.5 seconds memory limit per test 256 megabytes input standard input output standard out Put

Bomboslav likes to look out of the ' window in ' his room and watch lads outside playing shell famous. 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 "position".

Bomboslav noticed that guys are not very inventive, so the operator always swaps the "left shell" with the middle one during Odd moves (the third, fifth, etc.) and always swaps the middle shell with the right one during even (moves, second Rth, etc.).

Let's number shells from 0 to 2. Thus the left shell are assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball is placed beneath the shell, but he knows that exactly n movements were mad E by the operator and the ball is under Shell X at the end. Now him wonders, what was the initial position of the ball? Input

The ' The ' input contains a 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 is found after N movement S. Output

Print one integer from 0 to 2-the index of the shell where the ball is initially placed. Examples Input

4
2
Output
1
Input
1
1
Output
0
Note

In the ' the ', the ball was initially placed beneath the middle shell and the operator completed. During the 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.

The main effect of the topic:

Now there are three small boxes, of which there is a ball in a box. A total of n operations, the operating rules are:

① the odd number of times to swap the first and middle boxes.

② a couple of times, swapping the third and middle boxes.

Now known to operate N times after the ball in the X box (0,1,2), ask the initial time where the ball;


Ideas:


1, violence dozen forms to find the law can.

x==2 when the law: 2001122200112;

X==1 when the law: 021021021021;

X==0 when the law: 112200112200;


2, then according to the law to give the answer directly.


AC Code:

#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");}}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.