Codeforces777A Shell Game 2017-05-04 17:11 59人阅读 评论(0) 收藏
0.5 seconds
256 megabytes
standard input
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?
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.
Print one integer from 0 to 2 —
the index of the shell where the ball was initially placed.
4
2
1
1
1
0
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.
#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) 收藏的更多相关文章
- ZSTU4274 约素 2017-03-22 17:11 66人阅读 评论(0) 收藏
4274: 约素 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 1807 Solved: 467 Description 判断一个正整数n的约数个数 ...
- Singleton设计模式 分类: 设计模式 2014-12-03 17:54 59人阅读 评论(0) 收藏
实现方法: public class SingleTon<T> where T : class, new() { protected SingleTon() { } pri ...
- 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 ...
- Java中的日期操作 分类: B1_JAVA 2015-02-16 17:55 6014人阅读 评论(0) 收藏
在日志中常用的记录当前时间及程序运行时长的方法: public void inject(Path urlDir) throws Exception { SimpleDateFormat sdf = n ...
- strace使用详解(转) 分类: shell ubuntu 2014-11-27 17:48 134人阅读 评论(0) 收藏
(一) strace 命令 用途:打印 STREAMS 跟踪消息. 语法:strace [ mid sid level ] ... 描述:没有参数的 strace 命令将所有的驱动程序和模块中的 ...
- highgui.h备查 分类: C/C++ OpenCV 2014-11-08 18:11 292人阅读 评论(0) 收藏
/*M/////////////////////////////////////////////////////////////////////////////////////// // // IMP ...
- APP被苹果APPStore拒绝的各种原因 分类: ios相关 app相关 2015-06-25 17:27 200人阅读 评论(0) 收藏
APP被苹果APPStore拒绝的各种原因 1.程序有重大bug,程序不能启动,或者中途退出. 2.绕过苹果的付费渠道,我们之前游戏里的用兑换码兑换金币. 3.游戏里有实物奖励的话,一定要说清楚,奖励 ...
- 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 ...
- POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13598 Accepted: 5791 ...
随机推荐
- 【340】GIS related knowledge
mpk: 对地图文档以及所有引用的数据源进行打包可创建经过压缩的单个 .mpk 文件.参考,可以通过 Package Map 工具实现. Collector for ArcGIS Survey123 ...
- 基元线程同步构造之信号量(Semaphore)
信号量(semaphore)不过是由内核维护的 int32变量而已,(说通俗点就是好比一个线程容器里面允许执行的线程数,0计数就是允许执行的0个线程数,1就是允许执行的1个线程数,2就是允许执行的2个 ...
- Windows10系统一键结束所有运行程序
当电脑及其卡顿的时候,想打开任务管理器关掉所有运行的程序的时候,也会变得及其困难.因此之前你如果有犀利的小程序设置,这都不会是问题. 1)空白处右键-新建-快捷方式 2)将下列代码复制到下列框中(注意 ...
- gtftools软件简单介绍(我自己不建议用,因为我发现不好用)
1)背景 生物信息学研究经常涉及计算或提取基因的各种特征,如基因ID作图,GC含量计算和不同类型的基因长度,通过操纵基因模型,这些模型通常以GTF格式注释,可从ENSEMBL或GENCODE数据库获得 ...
- Zabbix安装(server和agent)及基本配置
简介 zabbix([`zæbiks])是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制 ...
- Oracle数据库迁移的几种方式
面试: 一.exp/imp逻辑备份与恢复: 二.Storage存储迁移: 将数据文件.控制文件.日志文件.spfile挂到新机器上,然后在新机器上启动数据库. 三.利用data guard迁移: 四. ...
- spotlight
spotlight - 必应词典 美['spɑt.laɪt]英['spɒt.laɪt] n.聚光灯:聚光灯照亮的地方:聚光灯照明圈:媒体和公众的注意 v.用聚光灯照:突出报道(以使公众注意) 网络射灯 ...
- Animation.wrapMode循环模式
WrapMode.Default:从动画剪辑中读取循环模式(默认是Once). WrapMode.Once:当时间播放到末尾的时候停止动画的播放. WrapMode.Loop:当时间播放到末尾的时候重 ...
- FileUpload控件实现单按钮图片自动上传并带预览显示
FileUpload控件实现单按钮图片自动上传并带预览显示 1.实现原理: FileUpload控件默认不支持服务端的ONCHANGE事件,此时用一种变通的方法借用客户端的onchange事件,调 ...
- onsubmit return false仍提交表单
博主之前遇到这样的问题,是因为代码有错,改正之后就正常了. 但今天确定代码没错,仍然return false提交表单. 总结网上各路大神的解释: 1.onsubmit的作用是防止form只有一个inp ...