CF1207E XOR Guessing

思路

设答案为 \(a\),第一次异或的数为 \(b\),第二次异或的数为 \(c\),则可以通过两次询问知道 \(a \oplus b\)\(a\oplus c\),所以 \(b\oplus c = (a \oplus b) \oplus (a\oplus c)\)

因为范围为 \([0,2^{14}-1]\),且每次询问只有 \(100\) 次,所以可以让第一次询问 \(\{1,2,\cdots,100\}\),第二次询问 \(\{1\times 2^7,2\times 2^7,\cdots,100\times 2^7\}\),这样 \(b\) 只会影响 \(b\oplus c\) 的前 \(7\) 位,\(c\) 只会影响 \(b\oplus c\) 的后 \(7\) 位,进而可以通过分解 \(b\oplus c\) 推出 \(b,c\),通过 \((a\oplus b)\oplus b\)\((a\oplus c)\oplus c\) 得到 \(a\)

代码

#include <bits/stdc++.h>
using namespace std;
int x1,x2,c1,c2;
signed main() {
	cout<<"? ";
	for(int i=1;i<=100;i++)
		cout<<i<<" ";
	cout<<endl;
	cin>>x1;
	cout<<"? ";
	for(int i=1;i<=100;i++)
		cout<<(i<<7)<<" ";
	cout<<endl;
	cin>>x2;
	cout<<"! "<<(x2^(((x1^x2)>>7)<<7))<<endl;
	return 0;
}
posted @ 2024-09-25 20:02  WuMin4  阅读(25)  评论(0)    收藏  举报