牛客周赛 Round 56 C-异或故事 题型:分类讨论

75 阅读1分钟

C-异或故事_牛客周赛 Round 56 (nowcoder.com)

思想

根据异或的性质我们得出,用1去异或上一个数n,如果n为奇数则得到n−1,否则我们会得到n+1,由此,们发现,直接用1去异或就好了嘛,但考虑特殊的两个数,输入为1或1e9时,我们发现,用1去异或得到的两个数为0和1e9+1,不在我们要求的范围内,所以我们特判一下这两个数即可

#include<bits/stdc++.h>
using namespace std;

void solve()
{
	int a;cin>>a;
	
	if(a==1e9)
	cout<<999999999<<" "<<1023<<endl;
	else if(a==1) cout<<2<<" "<<3<<endl;
	else
	{
		int ans=1^a;
		cout<<1<<" "<<ans<<endl; 
	}
}
int  main()
{
	int t;cin>>t;
	while(t--)
	solve();
	return 0;
}

image.png