题解:CF2001C Guess The Tree
Galaxy_zhao · · 题解
Codeforces 2001C Guess The Tree 题解
——这是一个令人头疼的交互题
题目大意
共
思路详解
通过观察不难发现,对于两个点
注意事项
注意,每做一次询问不要忘了刷新缓存区。
AC代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int P = 1e9 + 7;
const double F = 0.0000000001;
mt19937_64 mrand(random_device{}());
int Test, n, t = 0;
set<pair<int, int>> f;
pair<int, int> a[N];
int main() {
scanf("%d", &Test);
while (Test--) {
t = 0;
scanf("%d", &n);
int y;
for (int i = n; i > 1; i--) {
y = 1;
while (true) {
printf("? %d %d\n", y, i);
fflush(stdout);
int p;
scanf("%d", &p);
if (y == p) {
a[++t] = {y, i};
break;
}
y = p;
}
}
printf("! ");
for (int i = 1; i <= t; i++)
printf("%d %d ", a[i].first, a[i].second);
puts("");
fflush(stdout);
}
}
~886