0
点赞
收藏
分享

微信扫一扫

#804 div.2 A

西曲风 2022-07-12 阅读 23
#ifdefiosc++

#804 div.2 A_ios

知识总结:

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;
}




举报

相关推荐

0 条评论