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
  1. 4

  2. 2
Output
  1. 1
Input
  1. 1

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

Codeforces 777A Shell Game的更多相关文章

  1. 【codeforces 777A】Shell Game

    [题目链接]:http://codeforces.com/contest/777/problem/A [题意] 奇数次操作交换1,2位置的东西; 偶数此操作交换2,3位置的东西 给你操作的次数,和最后 ...

  2. 【循环节】 Codeforces Round #401 (Div. 2) A. Shell Game

    容易发现存在循环节. #include<cstdio> using namespace std; int n,x,a[3][6]={{0,1,2,2,1,0},{1,0,0,1,2,2}, ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. Codeforces Round #401 (Div. 2) 离翻身就差2分钟

    Codeforces Round #401 (Div. 2) 很happy,现场榜很happy,完全将昨晚的不悦忘了.终判我校一片惨白,小董同学怒怼D\E,离AK就差一个C了,于是我AC了C题还剩35 ...

  5. Shell替换

    如果表达式中包含特殊字符,Shell 将会进行替换.例如,在双引号中使用变量就是一种替换,转义字符也是一种替换. #!/bin/bash a= echo -e "Value of a is ...

  6. Shell特殊变量

    $ 表示当前Shell进程的ID,即pid $echo $$ 运行结果 特殊变量列表 变量 含义 $0 当前脚本的文件名 $n 传递给脚本或函数的参数.n 是一个数字,表示第几个参数.例如,第一个参数 ...

  7. shell变量

    定义变量 定义变量时,变量名不加美元符号($),如: variableName="value" 注意,变量名和等号之间不能有空格,这可能和你熟悉的所有编程语言都不一样.同时,变量名 ...

  8. 第一个shell脚本

    打开文本编辑器,新建一个文件,扩展名为sh(sh代表shell),扩展名并不影响脚本执行,见名知意就好. #!/bin/bash echo "Hello World !" &quo ...

  9. shell简介

    Shell作为命令语言,它交互式地解释和执行用户输入的命令:作为程序设计语言,它定义了各种变量和参数,并提供了许多在高级语言中才具有的控制结构,包括循环和分支. shell使用的熟练程度反映了用户对U ...

随机推荐

  1. Python学习日记:day8-------文件操作

    文件操作 1,文件路径:d:\xxxx.txt     绝对路径:从根目录到最后     相对路径:当前目录下的文件 2,编码方式:utf-8 3,操作方式:只读,只写,追加,读写,写读...... ...

  2. 每周.NET前沿技术文章摘要(2017-06-07)

    汇总国外.NET社区相关文章,覆盖.NET ,ASP.NET等内容: .NET .NET Core and .NET Framework Working Together, Or: The Magic ...

  3. 虚拟机创建流程中neutron代码分析(一)

    前言: 在openstack的学习当中有一说法就是网络占学习时间的百分之七十.这个说法或许有夸大的成分,但不可否认的是openstack中的 网络是及其重要的部分,并且难度也是相当大.试图通过nova ...

  4. 7、树莓派编程;gpio编程;led闪烁

    本博文仅作本人操作过程的记录,留作备忘.自强不息 QQ12226981 1.树莓派接口对照,一定要找到对应的引脚,不要接错了.我画上箭头. 2.安装 下载地址,https://git.drogon.n ...

  5. MVC 框架

    MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一种业务逻辑.数据.界面显示分离的方法组织代码 ...

  6. AngularJS 模板

    一个应用的代码架构有很多种.对于AngularJS应用,我们鼓励使用模型-视图-控制器(MVC)模式解耦代码和分离关注点.考虑到这一点,我们用AngularJS来为我们的应用添加一些模型.视图和控制器 ...

  7. [编织消息框架][JAVA核心技术]cglib动态代理

    先在mavne项目里添加cglib库 maven仓库搜索cglib版本 maven地址:http://mvnrepository.com/ 点击最新的版本 3.2.5 复制到pom.xml  depe ...

  8. Ubuntu 安装MyEclipse10

    Ubuntu 安装MyEclipse10 1.安装JDK 2.下载myeclipse.run 3.  现在假设你的 myeclipse.run 的路径是/home/yourname/myeclipse ...

  9. 有关opacity或RGBA设置颜色值及元素的透明值

    opacity声明来设置元素的透明值,当opacity设置元素的透明值,内部的文字及元素也会透明,通过RGBA设置的颜色值只针对当前元素,内部的文字及元素的透明值并未发生变化   opacity声明来 ...

  10. 我知道你不知道的负Margin

    现如今,负margin技术的应用可谓越来越广,任一个大型站点惊鸿一瞥之下都会有其身影所在.个人认为负margin技术是学习css路上必不可缺少的课题之一,许多高级应用及疑难杂症修复都可以使用负marg ...