Codeforces Round #554 (Div. 2) B. Neko Performs Cat Furrier Transform (二进制的位运算的设计与思考)

C++游戏开发入门:从环境配置到第一个完整项目 C++ 作为游戏开发领域的关键语言,其学习路径常因语法枯燥而令初学者却步。以项目驱动的方式学编程,能帮助学习者将变量、循环、函数、指针等基础概念融入实际游戏逻辑中,获得即时反馈与完整项目经验。掌握合适的开发环境是高效实践的前提,例如在 Windows 下使用 VS Code 搭配 MinGW-w64 编译器,配合调试器与构建脚本,即可搭建轻量可扩展的 C++ 游戏开发工作流。此类课程通常面向无基础人群,从控制台小游戏逐步过渡到带游戏循环的完整作品,过程中还需关注性能观察、素材授权与版本管理。无论你是刚接触编 阅读详情

B. Neko Performs Cat Furrier Transform

http://codeforces.com/contest/1152/problem/B

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 xx. A perfect longcat is a cat with a number equal 2m−12m−1 for some non-negative integer mm. For example, the numbers 00, 11, 33, 77, 1515 and so on are suitable for the perfect longcats.

In the Cat Furrier Transform, the following operations can be performed on xx:

  • (Operation A): you select any non-negative integer nn and replace xx with x⊕(2n−1)x⊕(2n−1), with ⊕⊕ being a bitwise XOR operator.
  • (Operation B): replace xx with x+1x+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 4040 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 4040 operations.

Input

The only line contains a single integer xx (1≤x≤1061≤x≤106).

Output

The first line should contain a single integer tt (0≤t≤400≤t≤40) — the number of operations to apply.

Then for each odd-numbered operation print the corresponding number nini in it. That is, print ⌈t2⌉⌈t2⌉ integers nini (0≤ni≤300≤ni≤30), denoting the replacement xx with x⊕(2ni−1)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.

Examples

input

Copy

39

output

Copy

4
5 3 

input

Copy

1

output

Copy

0

input

Copy

7

output

Copy

0

Note

In the first test, one of the transforms might be as follows: 39→56→57→62→6339→56→57→62→63. Or more precisely:

  1. Pick n=5n=5. xx is transformed into 39⊕3139⊕31, or 5656.
  2. Increase xx by 11, changing its value to 5757.
  3. Pick n=3n=3. xx is transformed into 57⊕757⊕7, or 6262.
  4. Increase xx by 11, changing its value to 63=26−163=26−1.

In the second and third test, the number already satisfies the goal requirement.

核心思想:寻找n值

39    ‭00100111‬

31    ‭00011111‬ 为  00100000减1;为2的5次方,n值5

56    ‭00111000‬

#include <bits/stdc++.h>
#include<windows.h>
#define ll long long int
#define mod 1000000007
//#define pii pair<int, int>
//#define fr(n) for (int i = 0; i < n; i++)
//#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;
vector<int> vi;

int x;
bool judge(int num)
{
    for( int i=0; i <= 21; i++)
    {
        if(   ( num &( 1<<i ) )==false  &&  (num >= ( 1<<i ) ) )
        {
            return false;
        }

    }
    return true;
}

int change(int num)
{
    //bool w = 0;
    for (int i = 21; i >= 0; i--)//2的20次方为1048576,不会超过20位
    {
        /*if ( ! (x & (1 << i)) )
            {
                if (w)
                {
                    vi.push_back(i + 1);
                    x ^= ((1 << (i + 1)) - 1);
                    break;
                }
            }
            else
                w = 1;
        //if (  (num & (1 << i) )==true && (num & (1 << (i-1) ) )==false )*/
        if (  (num & (1 << i) ) && !(num & (1 << (i-1) ) ) )
        {

            vi.push_back( i );
            num ^= ( (1 << i ) - 1);
            return num;
        }
    }
}

int main()
{
    int v = 0;//程序进行40次,奇数和偶数的集合各一半,所以只进位20次
    cin >> x;
    while (1)
    {
        if ( judge(x) )
        {
            break;
        }

        v++;
        x=change(x);
        if ( judge(x) )
        {
            break;
        }

        v++;
        x++;

    }

    cout << v << '\n';

    vector<int>::iterator it=vi.begin();
    for (; it!=vi.end(); it++)
        cout << *it << ' ';


}

 

[金仓数据库V8R6]更换授权 上传授权,使用mv license_xxx_0.dat /home/kingbase/KingbaseES/license.dat替换每个授权,并使用ls -l license.dat确保替换前后属主和权限不变。根据步骤1的数据目录位置,执行/home/kingbase/KingbaseES/Server/bin/sys_ctl -D /home/kingbase/KingbaseES/data reload使新的授权文件生效。该参数意义为授权剩余有效天数,查询结果为新授权中有效期间的天数即为替换成功。 阅读详情

相关推荐

给麒麟KylinOS服务器加把锁:手把手配置符合等保要求的密码强度策略

本文详细介绍了如何在麒麟KylinOS服务器上配置符合等保要求的密码强度策略,包括pwquality.conf和login.defs的核心参数设置、等保合规的进阶配置技巧以及企业环境中的平衡艺术。通过实战案例和测试方法,帮助管理员构建坚固的密码防线,确保系统安全。

weixin_33749242的博客 417

Codeforces Round #554 (Div. 2)B. Neko Performs Cat Furrier Transform

B. Neko Performs Cat Furrier Transform time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Cat Furrier Transform is a popular algorith...

微微风簇浪,散作满河星 442

9 海康视觉平台VisionMaster 上手系列:典型案例之螺丝机案例

海康视觉平台VisionMaster 上手系列:典型案例之螺丝机案例 快速入门 工业机器视觉 机器视觉

HuangGong2022的博客 7165

B. Neko Performs Cat Furrier Transform(思维题)

B. Neko Performs Cat Furrier Transform 思路: 一开始暴力就一直TLE,后来发现有规律。 eg:n = 10; n = 1010(2) 如果是A操作,可以异或一个值x将1010的末尾的0变为1,就是 1010^1 = 1011,(这样就消去了末尾的0,离全1的二进制数进了一步) 然后是B操作,1011+1 = 1100,(这样通过将靠前的0...

积少成多,水滴石穿 360

Arduino程序设计(十四)舵机控制实验(SG90)

本文介绍SG90舵机控制原理及实验,主要内容有:1、介绍SG90舵机;2、舵机0°~180°来回转动;3、串口控制舵机转动固定角度。(1)舵机是一种位置(角度)伺服的驱动器。舵机只是一种通俗的叫法,其实质是一个伺服马达。在需要角度不断变化并可以保持的控制系统中应用广泛。如遥控机械人、飞机模型等。(2)舵机的转动角度为0~180°,其内部结构包括电机,控制电路和机械结构三部分。电机有三根线引出,分别接VCC、GNG和信号线。

Alice的博客 1万+

DeepSeek 框架和技术栈分析

DeepSeek 诞生于对更高效、更强大的深度学习计算和模型训练的追求。随着深度学习模型的规模不断增大,如大型语言模型(LLMs)和复杂的视觉模型,传统的框架在处理这些大规模模型时面临着性能瓶颈和资源利用效率低下的问题。DeepSeek 旨在解决这些问题,通过优化框架设计和采用先进的技术栈,实现更高效的模型训练和推理,同时降低计算成本。

yournameplease的专栏 1510

Codeforces Round #554 (Div. 2) 1152B - Neko Performs Cat Furrier Transform

笔记: 1. 2^i: 10000000 2^i-1:1111111 判断x是否是2^i: 1.找到位数范围,1e6为020,1e9为030,因为1e6约等于220,1e9约等于230 2.循环判断是否可以为1<<i,O(1)复杂度 判断x是否为2i-1,先加一,在判断是否为2i 2. 判断x的第i位数字,x>>i,从左往右找到x的第一个1,就是找到x的最大位i为1 从i的...

FreeGo~ 412

解决linux 2.5G网卡驱动问题

解决linux 2.5G网卡驱动问题 关键词:2.5G网卡驱动,ubuntu,安装,2.5G Ethernet LINUX driver,Realtek网卡驱动 由于2.5G网卡较新,各linux发行版的通用驱动已不适用,新装的系统会出现无法上网问题,由于国内网络环境去Realtek官网很难下载到驱动文件,故本文提供github上的2.5G Ethernet LINUX driver r8125 for kernel up to 5.6的版本驱动文件r8125-9.003.05.tar.bz2各位可以自

poorguy_aos的博客 1万+

Neko Performs Cat Furrier Transform

https://codeforces.com/contest/1152/problem/B 题解:模拟+贪心 /* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib&g...

无限迭代中...... 561

【Python计量】linearmodels面板数据回归(一)

我们以伍德里奇《计量经济学导论现代方法》的”第14章高级面板数据方法“的案例14.1为例,使用jtrain中的数据来进行固定效应估计。

mfsdmlove的博客 9275

SAP-ABAP:SAP HANA性能神器FDA:是极速查询的引擎,也是CPU过载的元凶

在SAP S/4HANA的世界里,有一个被ABAP开发者们既爱又怕的特性——Fast Data Access(FDA),它能将性能提升百倍,也能让CPU瞬间飙升。本文将带您全面解剖这一核心机制。

baidu_35680696的博客 847

B. Neko Performs Cat Furrier Transform

#include <iostream> using namespace std; #include <vector> #define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); vector<int>res;//这里是装数字,也就是A步骤操作的时候,操作的位数 int ...

遇见生活 225

PX4从放弃到精通(十九):串口驱动

文章目录前言一、创建进程二、编写驱动 前言 硬件: PIXHAWK4 USB转串口模块 软件: Ubuntu18.04 PX4 1.11.3固件 QGC地面站 串口助手 一、创建进程 参考:https://mbot1.blog.csdn.net/article/details/122587617 二、编写驱动 .........

超维空间科技的博客 4597

Codeforces Round #554 (Div. 2) B - Neko Performs Cat Furrier Transform

题目链接:https://codeforces.com/contest/1152/problem/B 题意:给你一个数x,你可以对其进行两种操作: 操作A: 选择一个非负数:n,然后将x与(2^n - 1)进行异或 操作B: 将x自增1 其中第一种操作必选为A,然后紧跟着B操作,即操作必须为ABAB....A或ABAB..AB。要求最后的x可以变为 即x = (2^m - 1) ...

vaeloverforever的博客 202

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

B. Neko Performs Cat Furrier Transform---异或的性质运用--Codeforces Round #554 (Div. 2)

Neko Performs Cat Furrier Transform time limit per test 1 second memory limit per test 256 megabytes 题目链接http://codeforces.com/problemset/problem/1152/B emmm,题目大意:给你一个数n,让你对他进行t次操作使得它的值为2x-1,你第一次只能...

孤风的博客 444

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Codeforces Round #554 (Div. 2) B Neko Performs Cat Furrier Transform & C Neko does Maths

B. Neko Performs Cat Furrier Transform 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 t...

LSC__lsc的博客 399

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Codeforces Round #554 (Div. 2)B. Neko Performs Cat Furrier Transform【模拟】

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 lon...

独钓门前月 414

Codeforces Round #554 (Div. 2) Neko Performs Cat Furrier Transform 异或

B. Neko Performs Cat Furrier Transform time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Cat Furrier Transform is a popular algorith...

云乐 189

Codeforces Round #554 (Div. 2)-B. Neko Performs Cat Furrier Transform

B. Neko Performs Cat Furrier Transform Descpiption: Cat Furrier Transform is a popular algorithm among cat programmers to create longcats. As one of the greatest cat programmers ever exist, Neko wants...

zhe 320

B. Neko Performs Cat Furrier Transform Codeforces Round #554 (Div. 2)

B. Neko Performs Cat Furrier Transform time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Cat Furrier Transform is a popular algorith...

NULL 188

Codeforces Round #554 (Div. 2) 1152B. Neko Performs Cat Furrier Transform

学了这么久,来打一次CF看看自己学的怎么样吧 too young too simple 1152B. Neko Performs Cat Furrier Transform 题目链接:"https://codeforces.com/contest/1152/problem/B" 题目大意:将数字经过一系列的处理 (轮流进行加法操作和异或操作且加数和异或数有要求,加法只能加一,异或只能对2的n次方-...

weixin_30707875的博客 121

Codeforces Round #554 (Div. 2) Problem B. Neko Performs Cat Furrier Transform

https://codeforces.com/contest/1152/problem/B 大致思路是找到二进制n的第一个0, 然后模拟,与位操作有关 #include<algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cst...

qq_42426141的博客 186

Codeforces Round #554 (Div. 2) B. Neko Performs Cat Furrier Transform(思维题+log2求解二进制位数的小技巧)...

传送门 题意:   给出一个数x,有两个操作:   ①:x ^= 2k-1;   ②:x++;   每次操作都是从①开始,紧接着是②   ①②操作循环进行,问经过多少步操作后,x可以变为2p-1的格式?   最多操作40次,输出操作数和所有操作中步骤①的操作数的k; 我的思路:   操作①每次都是异或 (k-1) 个1;   我们最终的结果是将 x 变为(p-1)个1; ...

weixin_30617561的博客 104

Codeforces Round #554 (Div. 2)

A. Neko Finds Grapes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output On a random day, Neko foundnntreasure chests andmmkeys. ...

curry___的博客 607
上一篇: 归并排序算法( 分而治之算法,O(nlogn)和快排算法速度一样 )
下一篇: 最长递增子序列 或者 最长不下降子序列 的三种算法
while_black
博客等级 码龄9年 25粉丝 57原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值