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 小时前
Claude Code源码分析——Claude Code Agent Loop 详细设计文档
java·开发语言·人工智能·ai
超龄编码人2 小时前
Qt Widgets Designer QTabWidget无法添加布局
开发语言·qt
直奔標竿2 小时前
Java开发者AI转型第二十六课!Spring AI 个人知识库实战(五)——联网搜索增强实战
java·开发语言·人工智能·spring boot·后端·spring
Python大数据分析@2 小时前
CLI一键采集,使用Python搭建TikTok电商爬虫Agent
开发语言·爬虫·python
@小码农2 小时前
2026年3月Scratch图形化编程等级考试一级真题试卷
开发语言·数据结构·c++·算法
这儿有一堆花2 小时前
住宅代理(Residential Proxy)技术指南
开发语言·数据库·php
一只大袋鼠2 小时前
Java进阶:CGLIB动态代理解析
java·开发语言
秦ぅ时2 小时前
保姆级教程|OpenAI tts-1-hd模型调用全流程(Python+curl+懒人用法)
开发语言·python
Joseph Cooper3 小时前
Linux HID 子系统实战:从虚拟键盘到 input 事件上报
linux·c语言·计算机外设
Eiceblue3 小时前
使用 C# 将 Excel 转换为 Markdown 表格(含批量转换示例)
开发语言·c#·excel