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();
	}
}
相关推荐
RuoZoe8 天前
重塑WPF辉煌?基于DirectX 12的现代.NET UI框架Jalium
c语言
祈安_11 天前
C语言内存函数
c语言·后端
郑州光合科技余经理13 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo12313 天前
matlab画图工具
开发语言·matlab
dustcell.13 天前
haproxy七层代理
java·开发语言·前端
norlan_jame13 天前
C-PHY与D-PHY差异
c语言·开发语言
多恩Stone13 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
QQ40220549613 天前
Python+django+vue3预制菜半成品配菜平台
开发语言·python·django
czy878747513 天前
除了结构体之外,C语言中还有哪些其他方式可以模拟C++的面向对象编程特性
c语言
遥遥江上月13 天前
Node.js + Stagehand + Python 部署
开发语言·python·node.js