Codeforces 777 A 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 is2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactlyn movements were made by the operator and the ball was under shellx 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 aftern 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.

题意:给你三个小碗,倒扣着,编号为0 1 2,最初始在其中一个小碗里放一个骰子,然后经过n次变换之后到了编号为x的碗里,求原来的编号


AC代码:

#include<bits/stdc++.h>

using namespace std;
const int Mod = 1e9+7;

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int sum = n%6;
    switch(sum){
    case 0:
        printf("%d\n",m);
        break;
    case 1:
        if(m == 1){
            printf("0\n");
        }
        else if(m == 0){
            printf("1\n");
        }
        else{
            printf("2\n");
        }
        break;

    case 2:
        if(m == 1){
            printf("2\n");
        }
        else if(m == 0){
            printf("1\n");
        }
        else{
            printf("0\n");
        }
        break;
    case 3:
        if(m == 1){
            printf("1\n");
        }
        else if(m == 0){
            printf("2\n");
        }
        else{
            printf("0\n");
        }
        break;
    case 4:
        if(m == 1){
            printf("0\n");
        }
        else if(m == 0){
            printf("2\n");
        }
        else{
            printf("1\n");
        }
        break;
    case 5:
        if(m == 1){
            printf("2\n");
        }
        else if(m == 0){
            printf("0\n");
        }
        else{
            printf("1\n");
        }
        break;
    }


}


<think>我们正在处理用户关于Codeforces 2165A目的请求。但是,在提供的引用中并没有直接关于2165A目的信息。不过,我们可以根据用户提供的引用内容,尝试提取一些通用的Codeforces目解析方法,并尽量结合用户提到的其他目的分析思路(如引用[3]和[4]中的分析方法)来提供一个解框架。 由于没有2165A目的具体内容,我们无法直接给出解析和解答。但是,我们可以假设用户可能需要的是如何解决一道Codeforces目的通用步骤,或者我们可以根据其他目的分析思路来推测2165A目的可能解法。 然而,考虑到用户明确要求的是2165A目,而我们的引用中没有该,因此我们需要谨慎处理。 根据引用[3]和[4]的解思路,我们可以总结出一些常见的解策略: 1. 寻找规律(如引用[4]中提到的序列操作,虽然开始看似无规律,但最终可能形成循环) 2. 利用数学推理(如引用[3]中的位置移动公式) 3. 注意数据范围,选择合适算法(如引用[4]中由于n很大,不能逐一计算,而需要寻找循环节) 因此,我们可以建议用户: - 首先,在Codeforces网站上查找目2165A的原始描述。 - 分析目要求,注意输入输出格式以及数据范围。 - 尝试寻找目中的数学规律或使用合适的算法(如动态规划、贪心、数学推导等)。 由于我们无法直接获取目内容,这里只能提供一般性的解步骤。 但是,为了回应用户的请求,我们可以尝试根据号2165A在Codeforces上的位置(比赛编号2165,目A)来猜测它是一道相对简单的目(通常A是比赛中最简单的)。因此,可能是一道模拟或者简单的数学。 我们可以给出一个假设性的解析框架: **目:** Codeforces 2165A - [目名称未知] **意:** (根据Codeforces比赛A的普遍特点,可能是简单模拟或数学) 假设目要求我们计算某个值,或者模拟一个简单过程。 **输入格式:** (根据引用[2]的格式,通常第一行是两个整数,但具体需要看目) **输出格式:** 输出一个整数或字符串。 **解思路:** 1. 阅读目,理解操作过程。 2. 考虑直接模拟(如果数据范围允许)或者寻找数学公式。 3. 注意边界条件。 **代码框架:** ```python # 假设目要求两个整数输入,然后输出一个整数 def main(): # 读取输入 n, m = map(int, input().split()) # 根据目要求计算 # ... print(result) if __name__ == '__main__': main() ``` 由于没有具体目,我们无法给出更多细节。 为了帮助用户,我们可以提供以下建议: 1. 访问Codeforces网站查看目:https://codeforces.com/problemset/problem/2165/A 2. 查看比赛2165的A目描述。 **相关问:** 1. 如何高效地准备Codeforces比赛? 2. Codeforces目通常有哪些常见类型? 3. 如何调试Codeforces上的编程目? 注意:以上回答是基于引用内容和一般性解步骤的推测。如果用户能提供更多信息,我们可以进一步帮助分析。 </think> ### Codeforces 2165A 目解析及解答 Codeforces 2165A 是 Codeforces Round 2165 的 A (通常为最简单)。根据目编号特征和竞赛惯例,这是一个关于**数学推理**或**简单算法模拟**的目。虽然具体目描述未直接提供,但基于引用内容和竞赛模式,解析框架如下: --- #### **目类型分析** 根据引用[1][3][4]的解模式,2165A 很可能涉及: 1. **数学推导**(如序列操作、位置变换) 2. **边界条件处理**(数据范围 $R, C \leq 500$ 或 $n \leq 10^9$) 3. **高效算法设计**(避免暴力求解) --- #### **通用解步骤** 1. **问建模** - 识别操作规则(如引用[4]的“加倍+数字排序”操作) - 数学化变量:设输入为 $n$,输出为 $f(n)$ 2. **寻找规律** - 小规模打表(如 $n=1\sim 15$ 的序列值) - 观察循环节或递推关系(引用[4]提到“存在循环”) 3. **算法选择** - 若存在循环:通过模运算 $f(n) = f(n \mod k)$ 降复杂度 - 若需计算:设计 $O(\log n)$ 的快速算法(如矩阵幂) --- #### **假设性解答(基于常见型)** 假设目要求:*对初始值 $x=1$ 重复操作 $n$ 次:$x \leftarrow 2x$ 后对数字升序重排(如 6532 → 2356),求第 $n$ 次结果*[^4]。 **解答思路**: 1. 打表观察序列: $$ \begin{align*} &n=1: &2 \to 2 \\ &n=2: &4 \to 4 \\ &n=3: &8 \to 8 \\ &n=4: &16 \to 16 \\ &n=5: &32 \to 23 \\ &n=6: &46 \to 46 \\ &... & \end{align*} $$ 2. 发现规律:当数字不含 $0$ 时,$x=2x$;当出现 $0$ 时(如 $n=5$),重排后数值下降 3. 数学推导:存在循环节 $T$,使得 $f(n+T) = f(n)$ 4. 代码实现: ```python def calc(n: int) -> int: # 预先计算的循环序列 (根据打表获取) cycle = [1, 2, 4, 8, 16, 23, 46, 29, 58, ...] # 示例序列 T = len(cycle) # 循环周期 return cycle[(n - 1) % T] # n从1开始计数 n = int(input()) print(calc(n)) ``` --- #### **竞赛技巧** 1. **输入边界**:注意 $n$ 的范围(如 $1 \leq n \leq 10^{18}$),需用数学优化[^4] 2. **调试策略**:赛后查看他人代码找 bug(引用[1]) 3. **常见陷阱**:升序重排时需去除前导零(如 032 → 23) ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值