-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2024_01_30_C.cpp
50 lines (46 loc) · 1.34 KB
/
2024_01_30_C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<bits/stdc++.h>
using namespace std;
long long xoor(long long a, long long b, long long r){
return abs((a^r) - (b^r));
}
int binaryToDecimal(string binary) {
long long decimal = 0;
int power = 0;
for (int i = binary.length() - 1; i >= 0; --i) {
if (binary[i] == '1') decimal += pow(2, power);
power++;
}
return decimal;
}
void tc(){
unsigned long long a, b, r;
cin >> a >> b >> r;
long long ans = 1e18;
string bin_a = bitset<64>(a).to_string();
string bin_b = bitset<64>(b).to_string();
string bin_r = bitset<64>(r).to_string();
cout << "r:" + bin_r << endl;
string x = "";
auto it = find(bin_r.begin(), bin_r.end(), '1');
int first_index = (it != bin_r.end()) ? distance(bin_r.begin(), it) : 64;
cout << "first index = 1:" + first_index << endl;
int sum = 0;
for(int i = 0; i < 64; i++){
string max_bin_i = "" + bin_r[i];
if(bin_a[i] == bin_b[i] or i < first_index) x += "0";
else{
if(i > first_index){
if(sum > 0) x += "" + bin_a[i];
else if(sum < 0) x += "" + bin_b[i];
else x += "0";
}
else x += "0";
}
}
cout << "x:" + x << endl;
cout << xoor(a, b, binaryToDecimal(x)) << endl;
}
int main(){
int t; cin >> t;
while (t--) tc();
}