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

基于phpstudy搭建pikachu靶场 一、phpstudy下载安装配置 phpstudy介绍 简单介绍一下phpstudy,详细请参考百度解读。pikachu是基于PHP环境搭建的,需要数据库支持,所以装pikachu之前需要先安装它需要的环境,就像你养鱼需要给它提供水环境一样。安装phpstudy能满足pikachu的需求,所以先安装phpstudy。 phpStudy是一个PHP调试环境的程序集成包。该程序包集成最新的Apache+PHP+MySQL+phpMyAdmin+ZendOptimizer,一次性安装,无须配置即可使用,是 阅读详情

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 << ' ';


}

 

【报错】ImportError: libpython3.10.so.1.0: cannot open shared object file: No such file or directory ImportError: libpython3.10.so.1.0: cannot open shared object file: No such file or directory 阅读详情

相关推荐

普通人也能看懂的Transformer源代码解释(PyTorch)

Transformer源代码解释之PyTorch篇 章节 词嵌入 位置编码 多头注意力 搭建Transformer 在这里插入图片描述 词嵌入 Transformer本质上是一种Encoder,以翻译任务为例,原始数据集是以两种语言组成一行的,在应用时,应是Encoder输入源语言序列,Decoder里面输入需要被转换的语言序列(训练时)。一个文本常有许多序列组成,常见操作为将序列进行一些预处理(如词切分等)变成列表,一个序列的列表的元素通常为词表中不可切分的最小词,整个文本就是一个大列表,元素为一个一

qq_50974223的博客 4167

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

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

Java utgard连接OPC问题记录

怎么开启是个问题, 是在引入openscada的jar包里的Sever类中修改,这就犯难了, 其实没必要, 只要在自己项目下创建与openscada中Server类相同的路径,并复制Server过去改就行了, 项目会优先使用本地类,像下面这样。奇迹发生了,0x00000005解决. 注: 我的安全补丁编码跟网上查到的并不一样, 所以最初没有删,后来全都删了就好了,这个编码规则咱也不知道.安全日志中记录用户登录行为, OPC通信需要使用Windows系统用户进行登录, 如果用户名密码错误这里会有相关记录.

wangxin1949的博客 2840

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

使用electron静默打印

使用electron静默打印 1.使用electron打印的理由 很多情况下程序中使用的打印都是用户无感知的。并且想要灵活的控制打印内容,往往需要借助打印机给我们提供的api再进行开发,这种开发方式非常繁琐,并且开发难度较大。 electron提供的打印api可以非常灵活的控制打印设置的显示,并且可以通过html来书写打印内容。 2.api ele...

w1366352655的博客 945

SAN存储与协议,了解SCSI、FC和ISCSI

在前面我们介绍SAN存储及iSCSI协议的时候了解到SAN存储其实是一个CS架构的系统。存储系统本身就是整个系统的服务端。以IP-SAN(也就是基于iSCSI的SAN存储)为例,其整体架构如图1所示。 图1 CS架构 对于存储系统来说,通常是由专业的存储厂商提供,比较知名的如EMC、NetAPP、IBM和日立等等。国内存储厂商也迅速崛起,比较知名的如华为、宏杉、浪潮和同友等等。另外,还有一些小的存储厂商,他们往往集中在某个领域,比如专注文件系统或者块存储等等。 除了专业的存储设备外,其实Linux

shuningzhang的专栏 2685

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

threejs中使用Reflector实现出倒影效果,并实现背景透明的效果(Reflector镜面背景透明, 倒影弱化)

在项目中遇到要实现倒影效果,threejs给我们提供了Reflector,可以轻松完成镜面效果,实现倒影。但背景不透明;并且反射出的倒影太亮了;网上没搜到解决方案, 自己修改了下源码实现了想要的效果,做个记录...

weixin_40856652的博客 5721

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

QML 果冻抖动:用 Scale 动画模拟 Q 弹反馈

介绍果冻抖动效果:点击后卡片通过多段 ParallelAnimation 实现 Scale X/Y 反向缩放和逐步衰减,模拟果冻弹性形变;进阶版本加入小幅 Rotation 增加活泼感,适合游戏、儿童应用等趣味反馈场景。

u011186532的专栏 425

【智能模型系列】基于Unity和MediaPipe【手部追踪+手势识别】系统开发指南

在本文中,我将详细介绍一个基于MediaPipe的Unity手势识别系统,该系统能够识别多种常见手势(如拳头、点赞、胜利手势等),并提供完整的事件系统来处理手势状态变化。这个系统非常适合用于VR/AR交互、手势控制游戏或任何需要自然用户界面的应用场景。

纯技术流日常开发商业开发记录总结等 583

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

推荐系统[八]算法实践总结V3:重排在快手短视频推荐系统中的应用and手淘信息流多兴趣多目标重排技术

快手推荐系统包括了传统的召回、粗排、精排、Learning To Rank 的多目标排序、多目标预估等技术环节。而在这些模块之后的技术环节就属于重排序,主要包括手机端和服务端两部分。服务端通过传统服务器部署重排服务,包括序列重排、多源内容混排、多样性模块。端上部分包括端上重排模型和端上重排策略两部分。重排技术是快手十分重要的技术环节,它的发展速度远快于其他排序环节,属于较新的技术范畴。整个序列的价值并非单 item 效果的累计,如何使得序列价值最大化;

丨汀、的博客 1062

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

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

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

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

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

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

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

Codeforces - 1152B - Neko Performs Cat Furrier Transform

地址 https://codeforces.com/contest/1152/problem/B 原文地址 https://www.lucien.ink/archives/422/ 题意 给你一个 xxx ,让你在 404040 步之内把它变成 2n−12 ^ n - 12n−1 的形式,你一定会在奇数步将其异或上一个值 2k−12 ^ k - 12k−1 ,在偶数步将其自增 111 ,让你输出你...

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

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值