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. 首届阿里巴巴在线技术峰会,9位大V演讲整理!

    https://yq.aliyun.com/articles/57826 感谢参加阿里巴巴在线技术峰会.7月19日的3场专家分享:Blink.Docker.电商互动:7月20日的云数据库十大经典案 例 ...

  2. Interrupt handler

    1.处理器上的中断硬件关系图 2. 中断处理例程 3. 顶半部与底半部

  3. pod优先级与抢占测试

    # kubectl describe node k8s-n2Name:               k8s-n2Roles:              <none>Labels:      ...

  4. Analyzing Microarray Data with R

    1) 熟悉CEL file 从 NCBI GEO (http://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE24460)下载GSE24460. 将得到 ...

  5. dubbo 多协议和多注册中心

    一.配置dubbo多协议模式 1.默认协议 Dubbo缺省协议采用单一长连接和NIO异步通讯,适合于小数据量大并发的服务调用,以及服务消费者机器数远大于服务提供者机器数的情况.Dubbo缺省协议不适合 ...

  6. 百度BAE的使用

  7. 百度Cafe原理--Android自动化测试学习历程

    主要讲解内容及笔记: 一.Cafe原理 Cafe是一款自动化测试框架,解决问题:跨进程测试.快速深度测试 官网:http://baiduqa.github.io/Cafe/ Cafe provides ...

  8. models渲染字典&form表单上传文件&ajax上传文件

    {# {% for u in teacher_d.keys %}#} {# {% for u in teacher_d.values %}#} {% for k,u in teacher_d.item ...

  9. vmware搭建vSAN提示磁盘不合格或者看不到磁盘的解决办法

    1.如果磁盘不合格,或者在创建磁盘组的时候看不到该磁盘,一般的原因都是该磁盘有其他分区,可以使用下面的方法来解决 a.首先开启esxi主机的ssh功能 b.登陆到esxi的后台 c. ls /dev/ ...

  10. Devexpress ChartControl 柱状图简单例子

    //using DevExpress.XtraEditors; //using DevExpress.XtraCharts; // Create an empty chart. ChartContro ...