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 ...
随机推荐
- python学习日记:day11----装饰器进阶
1.wraps from functools import wraps def wrapper(func): #func = holiday @wraps(func)#输出holiday的函数名 de ...
- RabbitMQ 1-入门学习
环境: 软件环境MacOS ,Homebrew包管理工具 IDE: Eclipse 项目:Maven项目 1.安装RabbitMQ Server: 方式一:通过homebrew :终端执行:brew ...
- php-递归创建级联目录
方法一: function mk_dir($path_arr,$root){ if(!empty($path_arr)){ static $path;//每次保存上次调用的值 $path .= '/' ...
- Wamp环境搭建常见错误问题解决
第一点.对于apache + php + mysql 的版本的正确选择 问题:网上有些教学视频已经很早了,然后很多人照着来,完全和视频里讲的一样,但是结果就是搭建不成功. 出现问题原因:三件套的版本选 ...
- Linux(以CentOS6.5示例)下安装Oracle官方最新版JDK(JDK1.8)
本文地址http://comexchan.cnblogs.com/ ,作者Comex Chan,尊重知识产权,转载请注明出处,谢谢! 我们很多组件都需要使用Oracle最新版的JDK,所以需要在我们的 ...
- 鸟哥的linux私房菜学习-(三)X Window与文本模式的切换
通常我们也称文本模式为终端机接口, terminal 或 console喔!Linux默认的情况下会提供六个Terminal来让使用者登陆, 切换的方式为使用:[Ctrl] + [Alt] + [F1 ...
- Jenkins 学习笔记(一):我对 Jenkins 的宏观认识
Jenkins 是一个持续构建的系统,通过一周的了解熟悉,其逻辑似乎很简单. Jenkins 拓扑 Jenkins 逻辑 1. 从代码库拉取代码. 2. 处理代码. 对于需要编译的程序,需要进行处理, ...
- 对vuex的认识和简单理解
vuex概述 Vuex 是一个主要应用在中大型单页应用的类似于 Flux 的数据管理架构.它主要帮我们更好地组织代码,以及把应用内的的状态保持在可维护.可理解的状态. 但如果是简单的应用 ,就没有必要 ...
- ECMAScript 6新特性简记
ECMAScript 6.0是JavaScript语言的2015年6月的发布版. 一.let和const命令 let:用来声明变量,用法类似于var,但是只在let命令所在的代码块内有效. var a ...
- python键盘读入的input方法
今天了解了一下python,学了一些小东西,便存下了: input函数(raw_input在3.0版本没有,所以就不说了!) num = input ("输入一个数:") |备注 ...