QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#619544 | #8239. Mysterious Tree | nefugzh | TL | 1ms | 3692kb | C++17 | 3.1kb | 2024-10-07 14:37:00 | 2024-10-07 14:37:02 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 1e3 + 10;
//bool vis[N];
int interacter(int u, int v) {
cout << "? " << u << " " << v << endl;
int x;
cin >> x;
return x;
}
int main() {
int t;
cin>>t;
while (t--) {
int n;
cin>>n;
//memset(vis, 0, sizeof n * 1);
int cnt = 0;
int x, y;
if (n & 1) {
int len = n >> 1;
for (int i = 1; i <= len; i++) {
int tmp = interacter(i, n - i + 1);
cnt += tmp;
if (tmp) x = i, y = n - i + 1;
if (cnt >= 2) {
cout << "! 1" << endl;
break;
}
}
int mid = (n + 1) >> 1;
if (cnt == 0) {
if (interacter(mid, 1) && interacter(mid, n) && interacter(mid, 2)) {
cout << "! 2" << endl;
} else {
cout << "! 1" << endl;
}
} else if (cnt == 1) {
int x1 = 0, y1 = mid;
for (int i = 1; i <= n; i++) {
if (x1) break;
if (i != x && i != y) x1 = i;
}
if (interacter(x, x1)) {
if (interacter(x, y1)) {
cout << "! 2" << endl;
} else {
cout << "! 1" << endl;
}
} else if (interacter(y, x1)) {
if (interacter(y, y1)) {
cout << "! 2" << endl;
} else {
cout << "! 1" << endl;
}
}
}
} else {
int len = n >> 1;
for (int i = 1; i <= len; i++) {
int tmp = interacter(i, n - i + 1);
cnt += tmp;
if (tmp) x = i, y = n - i + 1;
if (cnt >= 2) {
cout << "! 1" << endl;
break;
}
}
if (cnt == 0) {
cout << "! 1" << endl;
} else if (cnt == 1) {
int x1 = 0, y1 = 0;
for (int i = 1; i <= n; i++) {
if (x1 && y1) break;
if (!x1 && i != x && i != y) x1 = i;
else if (i != y && i != x) y1 = i;
}
if (interacter(x, x1)) {
if (interacter(x, y1)) {
cout << "! 2" << endl;
} else {
cout << "! 1" << endl;
}
} else if (interacter(y, x1)) {
if (interacter(y, y1)) {
cout << "! 2" << endl;
} else {
cout << "! 1" << endl;
}
}
}
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3692kb
input:
2 4 0 1 1 0 4 0 1 0 1 1
output:
? 1 4 ? 2 3 ? 2 1 ? 2 4 ! 1 ? 1 4 ? 2 3 ? 2 1 ? 3 1 ? 3 4 ! 2
result:
ok Correct (2 test cases)
Test #2:
score: -100
Time Limit Exceeded
input:
87 13 0 1 0 0 0 0 0 1 1 15 0 0 1 0 0 0 0 0 1 1 7 1 0 0 0 1 1 15 1 0 1 19 0 0 0 0 0 0 0 0 1 0 1 1 20 1 0 0 0 0 0 0 0 0 0 0 0
output:
? 1 13 ? 2 12 ? 3 11 ? 4 10 ? 5 9 ? 6 8 ? 2 1 ? 12 1 ? 12 7 ! 2 ? 1 15 ? 2 14 ? 3 13 ? 4 12 ? 5 11 ? 6 10 ? 7 9 ? 3 1 ? 13 1 ? 13 8 ! 2 ? 1 7 ? 2 6 ? 3 5 ? 1 2 ? 7 2 ? 7 4 ! 2 ? 1 15 ? 2 14 ? 3 13 ! 1 ? 1 19 ? 2 18 ? 3 17 ? 4 16 ? 5 15 ? 6 14 ? 7 13 ? 8 12 ? 9 11 ? 9 1 ? 11 1 ? 11 10 ! 2 ? 1 20 ? 2 ...