找数字OD

#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>
#include <stack>
#include <sstream>
#include <list>
#include <queue>
using namespace std;

void ten2two(int x) {
	string s;
	while (x) {
		s.push_back((x & 1) + '0');
		x >>= 1;
	}
	reverse(s.begin(), s.end());
	cout << s << endl;
}

int force_for_cmp(int x) {
	int cnt = 0, ans = x;
	while (x) {
		cnt++;
		x = x & (x - 1);
	}
	while (true) {
		int y = ++ans, cnt1 = 0;
		while (y) {
			cnt1++;
			y = y & (y - 1);
		}
		if (cnt == cnt1) {
			return ans;
		}
	}
	return 0;
}
int main() {
	int x = 3495382;
	int y = x & (x - 1);
	int z = x - y;
	int y1 = y & (y - 1);
	int z1 = y - y1;
	int ans = 0;
	if (z1 == (z << 1)) {
		int t = y;
		int append = 0;
		while (t & z1) {
			append = (append << 1) + 1;
			t >>= 1;
		}
		ans = x + z + append;
	}
	else ans = y + (z << 1);
	ten2two(x);
	//ten2two(y);
	//ten2two(z);
	//ten2two(y1);
	//ten2two(z1);
	ten2two(ans);
	ten2two(force_for_cmp(x));
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值