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 mmax=1<<30;//这个没有用到,因为读错了题;
// 但是这个可以判断一个数,是不是2的倍数; 
int yh(int x)
{
	int n;
	int weishu;
	for(int i=1;x;i++)
	{
		if(x%2==0)//如果x是偶数的话,表明x的二进制形式最后一位 为0,和!(x&1)差不多的,
		//但是!(x&1)这个速度更快一点点,因为计算机对二进制形式比较熟悉; 
		{
			weishu=i;
		}
		x=x>>1;
		//每次右移一位因为我要找最前面的那个0 ,i正好是位数; 
		/* 比如第一个测试样例39
		 39的二进制为
		39= 100111  
		 移动一次:
		19= 10011
		 2次;
		9= 1001;
		 3次 
		4= 100
		 4次
		2= 10
		 5次
		1= 1
		 
		 
		39= 1+2+4+32; 
		 这时候 
		*/
		//cout<<"i = "<<i<<"  "<<weishu<<" ";	cout<<x<<" ";
	//	system("pause");
	
	}
//	cout<<weishu<<endl;
	res.push_back(weishu);
	return weishu;
}
int main()
{
	int n;
	cin>>n;
	if(mmax%(n+1)==0)//根据题目的规则来进行判断 
	{
		cout<<0<<endl;
	}
	else
	{
		int cnt=0;int x;
		while(1)
		{
			
			x=yh(n);
			x=1<<x;
			x=x-1;
		//	cout<<x<<endl;
			n=n^x;
			cnt++;
				if(mmax%(n+1)==0||res.size()>39)
			{
				if(res.size()>39)
				cout<<39<<endl;
				else
				cout<<cnt<<endl;
				bool kg=false;
				for(auto &a:res)
				{
					if(kg)
					cout<<" ";
					kg=true;
					cout<<a;
				}
				return 0;
			}
			n=n+1;
			cnt++;
		//	cout<<n<<endl;
			if(mmax%(n+1)==0||res.size()>40)
			{
				if(res.size()>40)
				cout<<40<<endl;
				else
				cout<<cnt<<endl;
				bool kg=false;
				for(auto &a:res)
				{
					if(kg)//为了防止格式错误 
					cout<<" ";
					kg=true;
					cout<<a;
				}
				return 0;
			}
		}
	}
	return 0;
}

题目链接:https://codeforces.com/contest/1152/problem/B

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值