CF1152B.Neko Performs Cat Furrier Transform
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Cat Furrier Transform is a popular algorithm among cat programmers to create longcats. As one of the greatest cat programmers ever exist, Neko wants to utilize this algorithm to create the perfect longcat.
Assume that we have a cat with a number x. A perfect longcat is a cat with a number equal 2m−1 for some non-negative integer m. For example, the numbers 0, 1, 3, 7, 15 and so on are suitable for the perfect longcats.
In the Cat Furrier Transform, the following operations can be performed on x:
- (Operation A): you select any non-negative integer n and replace x with x⊕(2n−1), with ⊕ being a bitwise XOR operator.
- (Operation B): replace x with x+1.
The first applied operation must be of type A, the second of type B, the third of type A again, and so on. Formally, if we number operations from one in the order they are executed, then odd-numbered operations must be of type A and the even-numbered operations must be of type B.
Neko wants to produce perfect longcats at industrial scale, thus for each cat Neko only wants to perform at most 40 operations. Can you help Neko writing a transformation plan?
Note that it is not required to minimize the number of operations. You just need to use no more than 40 operations.
猫毛变换(Cat Furrier Transform)是猫程序员中广为流传的一种算法,用于生成“长猫”(longcat)。作为有史以来最伟大的猫程序员之一,Neko 希望利用该算法创造出完美的长猫。
假设我们有一只编号为 x 的猫。一只“完美长猫”是指其编号等于 2m−1(其中 m 为某个非负整数)的猫。例如,数字 0、1、3、7、15 等均符合完美长猫的要求。
在猫毛变换中,可对 x 执行以下两种操作:
- (操作 A):任选一个非负整数 n,将 x 替换为 x⊕(2n−1),其中 ⊕ 表示按位异或运算符;
- (操作 B):将 x 替换为 x+1。
首次执行的操作必须为类型 A,第二次必须为类型 B,第三次又必须为类型 A,依此类推。形式化地说,若将操作按执行顺序从 1 开始编号,则所有奇数编号的操作必须为类型 A,所有偶数编号的操作必须为类型 B。
Neko 希望以工业化规模生产完美长猫,因此对每只猫,Neko 最多只愿执行 40 次操作。你能帮 Neko 设计一个变换方案吗?
注意:本题不要求最小化操作次数,你只需保证操作总数不超过 40 次即可。
输入格式
The only line contains a single integer x (1≤x≤106).
唯一的一行包含一个整数 x(1≤x≤106)。
输出格式
The first line should contain a single integer t (0≤t≤40) — the number of operations to apply.
Then for each odd-numbered operation print the corresponding number ni in it. That is, print ⌈2t⌉ integers ni (0≤ni≤30), denoting the replacement x with x⊕(2ni−1) in the corresponding step.
If there are multiple possible answers, you can print any of them. It is possible to show, that there is at least one answer in the constraints of this problem.
第一行应包含一个整数 t(0≤t≤40),表示需执行的操作次数。
随后,对每个编号为奇数的操作,输出该操作对应的数字 ni。即输出 ⌈2t⌉ 个整数 ni(0≤ni≤30),表示在对应步骤中将 x 替换为 x⊕(2ni−1)。
若存在多种可能的答案,输出任意一种即可。可以证明,在本题的约束条件下至少存在一个答案。
输入输出样例
输入#1
39
输出#1
4 5 3
输入#2
1
输出#2
0
输入#3
7
输出#3
0
说明/提示
In the first test, one of the transforms might be as follows: 39→56→57→62→63. Or more precisely:
- Pick n=5. x is transformed into 39⊕31, or 56.
- Increase x by 1, changing its value to 57.
- Pick n=3. x is transformed into 57⊕7, or 62.
- Increase x by 1, changing its value to 63=26−1.
In the second and third test, the number already satisfies the goal requirement.
在第一个测试中,其中一种变换过程可能如下:39→56→57→62→63。更准确地说:
- 选取 n=5,将 x 变换为 39⊕31,即 56。
- 将 x 加 1,其值变为 57。
- 选取 n=3,将 x 变换为 57⊕7,即 62。
- 将 x 加 1,其值变为 63=26−1。
在第二和第三个测试中,该数已满足目标要求。
输入解题思路,AI测评打分。不知道怎么写?