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();
	}
}
相关推荐
科雷软件测试18 小时前
Python中itertools.product:快速生成笛卡尔积
开发语言·python
OOJO19 小时前
c++---list介绍
c语言·开发语言·数据结构·c++·算法·list
笨笨饿20 小时前
29_Z变换在工程中的实际意义
c语言·开发语言·人工智能·单片机·mcu·算法·机器人
艾为电子21 小时前
【技术帖】让接口不再短命:艾为 C-Shielding™ Type-C智能水汽防护技术解析
c语言·开发语言
棉花骑士21 小时前
【AI Agent】面向 Java 工程师的Claude Code Harness 学习指南
java·开发语言
IGAn CTOU21 小时前
PHP使用Redis实战实录2:Redis扩展方法和PHP连接Redis的多种方案
开发语言·redis·php
环黄金线HHJX.1 天前
TSE框架配置与部署详解
开发语言·python
Vfw3VsDKo1 天前
Maui 实践:Go 接口以类型之名,给 runtime 传递方法参数
开发语言·后端·golang
Pyeako1 天前
PyQt5 + PaddleOCR实战:打造桌面级实时文字识别工具
开发语言·人工智能·python·qt·paddleocr·pyqt5
白藏y1 天前
【C++】muduo接口补充
开发语言·c++·muduo