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 ...
随机推荐
- dowhile
public class TestDoWhile { /**do while 至少执行一次 先斩后奏 * 测试dowhile */ public static void main(String[] a ...
- 全面解析PHP面向对象的三大特征
PHP面向对象的三大特征: 继承,封装,多态 一.继承 1.如何实现继承? 给子类使用extends关键字,让子类继承父类: class Student extends Person{} 2.实现继承 ...
- 预习 jdbc 技术简介
JDBC简介: JDBC全称为java database connectivity,是sun公司指定的java数据库连接技术的简称. 他是sun公司和数据库开发商共同开发出来的独立于DBMS的应用程序 ...
- springmvc DispatchServlet初始化九大加载策略(三)
7. initRequestToViewNameTranslator 请求视图名 它主要与视图解析有关,如果对ViewResolvers.ModelAndView.View等没有多大印象,可以先看第8 ...
- 第五章 二叉树(a)树
- SQL2008清空日志文件
--SQL2008清空日志文件(数据库和日志文件名一定要是原始文件名!!!)USE [master]GOALTER DATABASE DBData SET RECOVERY SIMPLE WITH N ...
- gridview 级联删除、dataset
gridview编辑列(不使用控件绑定数据源)需要如下代码:<asp:GridView ID="GridView1" runat="server" Aut ...
- c++ 中的符号与关键字
符号按照符号的ASC码数值从小到达排列,关键字按照英文字母排序. & [38] 位运算:取地址:左值引用[指针.引用都是可以做类型转换的] #include <iostream> ...
- 关于MySQL在内网中使用另一台机器访问的问题
要在内网中访问另一台机器的MySQL数据库,需要两步操作 一是把运行MySQL的机器的3306端口打开,最好是能限制访问IP保证安全性. 二是更改MySQL账户的访问权限.MySQL的root账户默认 ...
- div 自适应宽度
div 自适应宽度 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...