Codeforces 777A Shell Game
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.
题目链接:http://codeforces.com/problemset/problem/777/A
分析:找规律,纯粹找规律,你说枚举也行!我之前搞反了,连样例都没过,纠结了二十分钟才发现问题,AC了!
下面给出AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{ int n,m;
int a[]={,,};
while(scanf("%d",&n)!=EOF)
{
scanf("%d",&m);
if(n%==)
{
int k=n/;
if(k%==)
{
if(m==)
printf("0\n");
else if(m==)
printf("1\n");
else if(m==)
printf("2\n");
}
else if(k%==)
{
if(m==)
printf("0\n");
else if(m==)
printf("1\n");
else if(m==)
printf("2\n");
}
else if(k%==)
{
if(m==)
printf("0\n");
else if(m==)
printf("1\n");
else if(m==)
printf("2\n");
}
}
else
{
int t=(n+)/;
if(t%==)
{
if(m==)
printf("0\n");
else if(m==)
printf("1\n");
else if(m==)
printf("2\n");
}
else if(t%==)
{
if(m==)
printf("0\n");
else if(m==)
printf("1\n");
else if(m==)
printf("2\n");
}
else if(t%==)
{
if(m==)
printf("0\n");
else if(m==)
printf("1\n");
else if(m==)
printf("2\n");
}
}
}
return ;
}
Codeforces 777A Shell Game的更多相关文章
- 【codeforces 777A】Shell Game
[题目链接]:http://codeforces.com/contest/777/problem/A [题意] 奇数次操作交换1,2位置的东西; 偶数此操作交换2,3位置的东西 给你操作的次数,和最后 ...
- 【循环节】 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}, ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- Codeforces Round #401 (Div. 2) 离翻身就差2分钟
Codeforces Round #401 (Div. 2) 很happy,现场榜很happy,完全将昨晚的不悦忘了.终判我校一片惨白,小董同学怒怼D\E,离AK就差一个C了,于是我AC了C题还剩35 ...
- Shell替换
如果表达式中包含特殊字符,Shell 将会进行替换.例如,在双引号中使用变量就是一种替换,转义字符也是一种替换. #!/bin/bash a= echo -e "Value of a is ...
- Shell特殊变量
$ 表示当前Shell进程的ID,即pid $echo $$ 运行结果 特殊变量列表 变量 含义 $0 当前脚本的文件名 $n 传递给脚本或函数的参数.n 是一个数字,表示第几个参数.例如,第一个参数 ...
- shell变量
定义变量 定义变量时,变量名不加美元符号($),如: variableName="value" 注意,变量名和等号之间不能有空格,这可能和你熟悉的所有编程语言都不一样.同时,变量名 ...
- 第一个shell脚本
打开文本编辑器,新建一个文件,扩展名为sh(sh代表shell),扩展名并不影响脚本执行,见名知意就好. #!/bin/bash echo "Hello World !" &quo ...
- shell简介
Shell作为命令语言,它交互式地解释和执行用户输入的命令:作为程序设计语言,它定义了各种变量和参数,并提供了许多在高级语言中才具有的控制结构,包括循环和分支. shell使用的熟练程度反映了用户对U ...
随机推荐
- GitLab版本管理工具
第1章 GitLab管理 1.1 版本控制系统 版本控制系统(version control system)是记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统.版本控制系统不仅可以应用于 ...
- iOS Block的简单使用以及__block 和static修饰变量
简单的代码总结,不足之处多多指教. //简单的使用 -(void)blockOne{ ; int(^BlockOne)(int) = ^(int num2) { return number*num2; ...
- 最长回文子序列(LPS)
问题描述: 回文是正序与逆序相同的非空字符串,例如"civic"."racecar"都是回文串.任意单个字符的回文是其本身. 求最长回文子序列要求在给定的字符串 ...
- Intellij IDEA 像eclipse那样给maven添加依赖
打开pom.xml,在它里面使用快捷键:ALT+Insert ---->点击dependency 再输入想要添加的依赖关键字,比如:输个spring 出现下图: 根据需求选择版本,完成以后 ...
- Akka Serialization
Akka本身使用了Protocol Buffers来序列化内部消息(比如gossip message).Akka系统还可以配置自定义序列化机制. 配置conf akka { actor { ## 在a ...
- 查看内存和cpu
top: 主要参数 d:指定更新的间隔,以秒计算. q:没有任何延迟的更新.如果使用者有超级用户,则top命令将会以最高的优先序执行. c:显示进程完整的路径与名称. S:累积模式,会将己完成或消失的 ...
- Linux第三节整理 、增删改查、用户管理
帮助+基本文件管理+用户管理 1.怎么查看命令帮助 ls --help man ls :查看命令/man 5 file:查看配置文件 2.基本文件管理,通过{查,建,删,改} 四个维度介绍了不同的命令 ...
- Kotlin——最详细的抽象类(abstract)、内部类(嵌套类)详解
如果您对Kotlin很有兴趣,或者很想学好这门语言,可以关注我的掘金,或者进入我的QQ群大家一起学习.进步. 欢迎各位大佬进群共同研究.探索QQ群号:497071402 进入正题 在前面几个章节中,详 ...
- Codebase Refactoring (with help from Go)
Codebase Refactoring (with help from Go) 代码库重构(借助于Go) 1.摘要 Go应该添加为类型创建替代等效名称的能力,以便在代码库重构期间渐进代码修复.本文解 ...
- js 停止事件冒泡 阻止浏览器的默认行为(阻止a标签跳转 )
在前端开发工作中,由于浏览器兼容性等问题,我们会经常用到"停止事件冒泡"和"阻止浏览器默认行为". 1..停止事件冒泡 JavaScript代码 //如果提供了 ...