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 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.
- 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.
题目链接: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("0n");
18 else if(m==1)
19 printf("1n");
20 else if(m==2)
21 printf("2n");
22 }
23 else if(k%3==1)
24 {
25 if(m==2)
26 printf("0n");
27 else if(m==0)
28 printf("1n");
29 else if(m==1)
30 printf("2n");
31 }
32 else if(k%3==2)
33 {
34 if(m==1)
35 printf("0n");
36 else if(m==2)
37 printf("1n");
38 else if(m==0)
39 printf("2n");
40 }
41 }
42 else
43 {
44 int t=(n+1)/2;
45 if(t%3==0)
46 {
47 if(m==0)
48 printf("0n");
49 else if(m==2)
50 printf("1n");
51 else if(m==1)
52 printf("2n");
53 }
54 else if(t%3==1)
55 {
56 if(m==1)
57 printf("0n");
58 else if(m==0)
59 printf("1n");
60 else if(m==2)
61 printf("2n");
62 }
63 else if(t%3==2)
64 {
65 if(m==2)
66 printf("0n");
67 else if(m==1)
68 printf("1n");
69 else if(m==0)
70 printf("2n");
71 }
72 }
73 }
74 return 0;
75 }
- 跟着柴毛毛学Spring(2)——Bean的配置
- C++ 使用STL string 实现的split,trim,replace-修订
- 跟着柴毛毛学Spring(1)——纵观Spring
- MYSQL常用SQL汇总
- Linux 下设置SVN DIFF
- 剑指 offer代码解析——面试题38数字在排序数组中出现的次数
- 剑指 offer代码解析——面试题37两个链表的第一个公共结点
- 剑指 offer代码解析——面试题34丑数
- 剑指 offer代码解析——面试题35第一个只出现一次的字符
- Python内置数据结构之集合
- 剑指 offer代码解析——面试题32统计1到n中1出现的次数
- 剑指 offer代码解析——面试题26复杂链表的复制
- Linux软件安装(二)——RPM与YUM
- linux软件安装(一)——源码安装
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- python中可以声明变量类型吗
- keras中的History对象用法
- php session_decode函数用法讲解
- 解决python对齐错误的方法
- 详解pyinstaller生成exe的闪退问题解决方案
- PHP递归算法的简单实例
- Yii2框架操作数据库的方法分析【以mysql为例】
- 使用OpenCV实现道路车辆计数的使用方法
- python中tab键是什么意思
- PHP实时统计中文字数和区别
- PHP单例模式实例分析【防继承,防克隆操作】
- Python基于network模块制作电影人物关系图
- tp5(thinkPHP5框架)使用DB实现批量删除功能示例
- 统计PHP目录中的文件数方法
- python json.dumps() json.dump()的区别详解