思路:
根据异或的性质一位一位来搞。参考了https://blog.lucien.ink/archives/362/
实现:
1 #include <bits/stdc++.h> 2 using namespace std; 3 void out(char x, int a, int b) 4 { 5 cout << x << " " << a << " " << b << endl; 6 fflush(stdout); 7 } 8 int main() 9 { 10 int a, b; 11 char big = 'a'; 12 out('?', 0, 0); 13 cin >> a; 14 if (a == -1) big = 'b'; 15 int x = 0, y = 0; 16 for (int i = 29; i >= 0; i--) 17 { 18 int t = 1 << i; 19 x |= t; y &= ~t; 20 out('?', x, y); 21 cin >> a; 22 x ^= t; y ^= t; 23 out('?', x, y); 24 cin >> b; 25 if (a == -1 && b == 1) 26 { 27 x |= t; y |= t; 28 } 29 else if (a == 1 && b == -1) 30 { 31 x &= ~t; y &= ~t; 32 } 33 else if (a == b) 34 { 35 if (big == 'a') 36 { 37 x |= t; y &= ~t; 38 if (a == -1) big = 'b'; 39 } 40 else 41 { 42 x &= ~t; y |= t; 43 if (a == 1) big = 'a'; 44 } 45 } 46 } 47 out('!', x, y); 48 return 0; 49 }