codeforces1088D_Ehab and another another xor problem交互题

传送门

一道考验思维的交互题

大致思路就是从最高的二进制位向下询问

代入例子比如:

  5 6

  6 5

  7 4

  6 4

讨论一下

交互题的重点学会推理和归纳

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int n, a, b;
 5 
 6 inline int ask(int c, int d) {
 7     printf("? %d %d\n", c, d);
 8     fflush(stdout);
 9     int rt; scanf("%d", &rt);
10     return rt;
11 }
12 
13 int main() {
14     int big = ask(0, 0);
15     for (int i = 29; i >= 0; --i) {
16         int f = ask(a ^ (1 << i), b), s = ask(a, b ^ (1 << i));
17         if (f == s) {
18             if (big == 1) a ^= (1 << i);
19             else b ^= (1 << i);
20             big = f;
21         }
22         else if (f == -1) {
23             a ^= (1 << i), b ^= (1 << i);
24         }
25     }
26     printf("! %d %d\n", a, b);
27     return 0;
28 }

猜你喜欢

转载自www.cnblogs.com/Fo0o0ol/p/10091262.html