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.


———————————————————————————————————
题目的意思是给你3个杯子,其中一个有物品,每次奇数次交换0 1 两个,偶数次交换1 2两个,给出操作次数和最后物品的位置,求出物品起始位置
思路:找出6循环节,mod之后反向推

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
n%=6;
if(m==0)
{
if(n==1||n==2)
printf("1\n");
else if(n==3||n==4)
printf("2\n");
else
printf("0\n");
}
else if(m==1)
{
if(n==0||n==3)
printf("1\n");
else if(n==2||n==5)
printf("2\n");
else
printf("0\n");
}
else
{
if(n==4||n==5)
printf("1\n");
else if(n==0||n==1)
printf("2\n");
else
printf("0\n");
}
}
return 0;
}


Codeforces777A Shell Game 2017-05-04 17:11 59人阅读 评论(0) 收藏的更多相关文章

  1. ZSTU4274 约素 2017-03-22 17:11 66人阅读 评论(0) 收藏

    4274: 约素 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 1807  Solved: 467 Description 判断一个正整数n的约数个数 ...

  2. Singleton设计模式 分类: 设计模式 2014-12-03 17:54 59人阅读 评论(0) 收藏

    实现方法: public class SingleTon<T> where T : class, new() {     protected SingleTon() { }     pri ...

  3. Codeforces816A Karen and Morning 2017-06-27 15:11 43人阅读 评论(0) 收藏

    A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standar ...

  4. Java中的日期操作 分类: B1_JAVA 2015-02-16 17:55 6014人阅读 评论(0) 收藏

    在日志中常用的记录当前时间及程序运行时长的方法: public void inject(Path urlDir) throws Exception { SimpleDateFormat sdf = n ...

  5. strace使用详解(转) 分类: shell ubuntu 2014-11-27 17:48 134人阅读 评论(0) 收藏

    (一) strace 命令    用途:打印 STREAMS 跟踪消息. 语法:strace [ mid sid level ] ... 描述:没有参数的 strace 命令将所有的驱动程序和模块中的 ...

  6. highgui.h备查 分类: C/C++ OpenCV 2014-11-08 18:11 292人阅读 评论(0) 收藏

    /*M/////////////////////////////////////////////////////////////////////////////////////// // // IMP ...

  7. APP被苹果APPStore拒绝的各种原因 分类: ios相关 app相关 2015-06-25 17:27 200人阅读 评论(0) 收藏

    APP被苹果APPStore拒绝的各种原因 1.程序有重大bug,程序不能启动,或者中途退出. 2.绕过苹果的付费渠道,我们之前游戏里的用兑换码兑换金币. 3.游戏里有实物奖励的话,一定要说清楚,奖励 ...

  8. Hdu2204 Eddy's爱好 2017-06-27 16:11 43人阅读 评论(0) 收藏

    Eddy's爱好 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Subm ...

  9. POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13598   Accepted: 5791 ...

随机推荐

  1. xStream转换XML、JSON

        一. 简介 xStream可以很容易实现Java对象和xml文档互相转换, 可以修改某个特定的属性和节点名称,xStream提供annotation注解, 可以在JavaBean中完成对xml ...

  2. hibernate事务隔离机制

    事务的基本概念 ACID:A是atomicity(原子性),C是consistency(一致性),I是isolation(隔离性),D是durability(持久性) 事务隔离级别从低到高: 读取未提 ...

  3. FP-growth算法高效发现频繁项集(Python代码)

    FP-growth算法高效发现频繁项集(Python代码) http://blog.csdn.net/leo_xu06/article/details/51332428

  4. JDK、JRE和JAR区别(转载)

    JDK里面的工具也是用Java编写的,它们本身运行的时候也需要一套JRE,如C:/Program Files/Java/jdk1.5.x/目录下的JRE.而C:/Program Files/Java/ ...

  5. mysql备份的三种方式

    一.备份的目的 做灾难恢复:对损坏的数据进行恢复和还原需求改变:因需求改变而需要把数据还原到改变以前测试:测试新功能是否可用 二.备份需要考虑的问题 可以容忍丢失多长时间的数据:恢复数据要在多长时间内 ...

  6. Java8 Stream语法详解 2

    1. Stream初体验 我们先来看看Java里面是怎么定义Stream的: A sequence of elements supporting sequential and parallel agg ...

  7. MySql ERROR 1045 (28000): Access denied 错误

    [MySql ERROR 1045 (28000): Access denied 错误] 即登陆错误,使用MySql登陆时,需使正确的username/passwd.通过 -u -p 参数即可. My ...

  8. EasuyUI前后台传参

    package com.cn.eport.util; import java.util.List; import java.util.Map; public class PageHelper impl ...

  9. SpringMVC中ApplicationContext中的配置文件的问题(No bean named 'sessionFactory' is defined 已解决)

    在一个SpringMVC项目中, 连着两天不管怎么搞都是一直在报错, 报的最多的就是一个 Servlet.service() for servlet [springDispatcherServlet] ...

  10. python之信号量【Semaphore】

    # 互斥锁同时只允许一个线程更改数据,而Semaphore是同时允许一定数量的线程更改数据,比如 # 一个厕所有3个坑,那么最多只允许3个人上厕所,后面的人只能等里面有人出来了才能再进去 import ...