赛时代码75分求调
查看原帖
赛时代码75分求调
772284
Justskr楼主2025/1/2 21:36
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define dbug(x) (void)(cerr << #x " = " << x << endl)

ll n,s,t;
inline bool check(ll k){
	if(k < (ll)pow(2,n) && (s | k) == (ll)pow(2,n)-1) return 1;
	return 0;
}

int main(){
	//ios::sync_with_stdio(false);
	//cin.tie(0),cout.tie(0);
	
	ll T;
	cin >> T;
	while(T-- && cin >> n >> s >> t){
		ll m = pow(2,n);
		if(s == t) cout << 0;
		else if(check(t)) cout << (s^t);
		else {
			ll cost = 0;
			bitset<32> sbit(s),tbit(t); 
			for (int i = 0; i < n; i++) {
				if(!sbit[i] && tbit[i] || sbit[i] && !tbit[i]){
					cost += m - (ll)pow(2,i) -1;
				}
			}
			cout << cost; 
		}
		cout  << endl;
	}
	
	
	
	return 0;
}
2025/1/2 21:36
加载中...