Codeforces Round #401(Div. 2)A. Shell Game迴圈節規律 __Codeforces#401Div.

來源:互聯網
上載者:User

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

42
Output
1
Input
11
Output
0
Note

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



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.