Codeforces 777A Shell Game

简介: A. Shell Game time limit per test:0.5 seconds memory limit per test:256 megabytes input:standard input output:standard o...
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.

 题目链接:http://codeforces.com/problemset/problem/777/A

分析:找规律,纯粹找规律,你说枚举也行!我之前搞反了,连样例都没过,纠结了二十分钟才发现问题,AC了!

下面给出AC代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5 
 6     int n,m;
 7     int a[3]={0,1,2};
 8     while(scanf("%d",&n)!=EOF)
 9     {
10         scanf("%d",&m);
11         if(n%2==0)
12         {
13             int k=n/2;
14             if(k%3==0)
15             {
16                 if(m==0)
17                     printf("0\n");
18                 else if(m==1)
19                     printf("1\n");
20                 else if(m==2)
21                     printf("2\n");
22             }
23             else if(k%3==1)
24             {
25                 if(m==2)
26                     printf("0\n");
27                 else if(m==0)
28                     printf("1\n");
29                 else if(m==1)
30                     printf("2\n");
31             }
32             else if(k%3==2)
33             {
34                 if(m==1)
35                     printf("0\n");
36                 else if(m==2)
37                     printf("1\n");
38                 else if(m==0)
39                     printf("2\n");
40             }
41         }
42         else
43         {
44             int t=(n+1)/2;
45             if(t%3==0)
46             {
47                 if(m==0)
48                     printf("0\n");
49                 else if(m==2)
50                     printf("1\n");
51                 else if(m==1)
52                     printf("2\n");
53             }
54             else if(t%3==1)
55             {
56                 if(m==1)
57                     printf("0\n");
58                 else if(m==0)
59                     printf("1\n");
60                 else if(m==2)
61                     printf("2\n");
62             }
63             else if(t%3==2)
64             {
65                 if(m==2)
66                     printf("0\n");
67                 else if(m==1)
68                     printf("1\n");
69                 else if(m==0)
70                     printf("2\n");
71             }
72         }
73     }
74     return 0;
75 }

 

目录
相关文章
|
Shell
Shell 99乘法表
9 * 9 乘法表 第一种使用for去完成(for i in list, for i , for(())) 第二种使用while去完成 注意格式:注意对齐,显示的美观一点 1 * 1 = 1 2 * 1 = 2 2 * 2 = 4 … 9 * 1 = 9 …9 * 9 = 81
55 0
|
5月前
|
Shell
Shell猜数字游戏
Shell猜数字游戏
52 1
|
5月前
|
缓存 自然语言处理 Shell
xv6(19)SHELL交互程序
SHELL交互程序
83 0
|
5月前
|
Shell 开发工具
用shell脚本猜大小
用shell脚本猜大小
42 0
|
Shell
shell之case范例1
shell之case范例1
53 1
|
Shell 数据安全/隐私保护
shell之case范2
shell之case范例2
54 0
|
Shell Perl
Shell之小tip (1)
Shell之小tip :1. 查看服务器的基本信息。2.后台运行任务。3. find的一些用法。4.文件压缩打包5.sed、grep、awk三剑客。
67 0
|
运维 Java Shell
Shell学习(一):Hello World
Java程序员为什么要学习Shell呢? 1)需要看懂运维人员编写的Shell程序。 2)偶尔会编写一些简单Shell程序来管理集群、提高开发效率。
157 0
Shell学习(一):Hello World
|
Shell Linux 存储
自制操作系统Antz day10——实现shell(上)
在之前的任务中,我们已经通过直接操作显卡驱动完成了简单的图形化。接下来要实现一个简单的shell。
1345 0
|
Shell Linux
shell之if和case
语法 image.png if样例1 image.png 赋权并运行 image.png if样例2 说明:if 和中括号之间没有空格 if样例2 说明:if 和中括号之间没有空格 运行 运行 if样例3 说明:else后面没有then image.
1043 0