C. Bitwise Balancing

原题

C. Bitwise Balancing

解析

题意如图

我们要求 a , 其实 a 只要满足条件即可, 我们可以发现每一位都不会影响到其它位, 因此对每一位检查, 发现对b c a, d 有固定结果

b c a d

0 0 0 0

0 0 1 1

0 1 0 0

0 1 1 0

1 0 0 1

1 0 1 1

1 1 0 1

1 1 1 0

bcd 无法为 011 和 100, 其它皆可找到对应的 a

代码

cpp 复制代码
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int N = 200010;

int n, m, k, q, ans;

int a[N];

void solve()
{
	int b, c, d;
	cin >> b >> c >> d;
	
	int mask = 1;
	
	int a = 0, bb = 0, cc = 0, dd = 0;
	
	for (int i = 1; i <= 62; i ++ )
	{
		if (b & mask)
		{
			bb = 1;
		}
		else
		{
			bb = 0;
		}
		if (c & mask)
		{
			cc = 1;
		}
		else
		{
			cc = 0;
		}
		if (d & mask)
		{
			dd = 1;
		}
		else
		{
			dd = 0;
		}
		
		if(bb == 0 && cc == 1 && dd == 1)
		{
			cout << -1 << "\n";
			return;
		}
		
		if(bb == 1 && cc == 0 && dd == 0)
		{
			cout << -1 << "\n";
			return;
		}
		
		if(bb == 1 && cc == 1 && dd == 0)
		{
			a += mask;
		}
		
		if(bb == 0 && cc == 0 && dd == 1)
		{
			a += mask;
		}
		
		mask <<= 1;
	}
	
	cout << a << "\n";
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
	cin >> T;
	while (T -- )
	{
		solve();
	}
}
相关推荐
陈文锦丫2 小时前
MQ的学习
java·开发语言
liwulin05063 小时前
【PYTHON-YOLOV8N】如何自定义数据集
开发语言·python·yolo
青蛙大侠公主3 小时前
Thread及其相关类
java·开发语言
爱吃大芒果3 小时前
Flutter 主题与深色模式:全局样式统一与动态切换
开发语言·javascript·flutter·ecmascript·gitcode
云栖梦泽3 小时前
易语言数据库操作:结构化数据管理的核心
开发语言
电子硬件笔记4 小时前
Python语言编程导论第七章 数据结构
开发语言·数据结构·python
南棱笑笑生4 小时前
20251217给飞凌OK3588-C开发板适配Rockchip原厂的Buildroot【linux-5.10】后调通ov5645【只能预览】
linux·c语言·开发语言·rockchip
ulias2124 小时前
C++ 的容器适配器——从stack/queue看
开发语言·c++
Amewin4 小时前
window 11 安装pyenv-win管理不同的版本的python
开发语言·python
lionliu05194 小时前
WebAssembly (Wasm)
java·开发语言·wasm