知识总结:
XOR异或,就是^符号。不同则1。
思路:
构造:只要输出任意一组答案。
构造 0 0 ?
(0^0)+(?^0)+(0^?)=n
易得2*(?^0)=n
(?^0)=n / 2
要求n必须是偶数
当n是奇数,就不能构造这一种答案。输出-1
奇数输出-1
偶数输出0 0 n/2
写法1:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e9 + 5;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef LOCAL
FILE *p = fopen("input.txt", "a+");
fclose(p);
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t; cin >> t;
while(t--){
int n; cin >> n;
if(n % 2 == 1) cout << -1 << "\n";
else cout << 0 << " " << 0 << " "<< n / 2 << "\n";
}
return 0;
}
写法2:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e9 + 5;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef LOCAL
FILE *p = fopen("input.txt", "a+");
fclose(p);
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t; cin >> t;
while(t--){
int n; cin >> n;
if(n & 1) cout << -1 << "\n";//这里不同
else cout << 0 << " " << 0 << " "<< n / 2 << "\n";
}
return 0;
}