QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#613629 | #8239. Mysterious Tree | mojimoon | WA | 2ms | 3884kb | C++14 | 1.8kb | 2024-10-05 14:22:05 | 2024-10-05 14:22:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
/*
interactive problem
judge if the tree is a star or a chain
a star has 1 node with degree n-1 and the rest with degree 1
a chain has 2 nodes with degree 1 and the rest with degree 2
max number of queries allowed is n/2+4
1=chain, 2=star
*/
int n;
int query(int x, int y) {
printf("? %d %d\n", x, y);
fflush(stdout);
int r;
scanf("%d", &r);
return r;
}
void answer(int x) {
printf("! %d\n", x);
fflush(stdout);
}
int solve(int x, int y) {
int z = -1, w = -1;
for (int i = 1; i <= n; i++) {
if (i != x && i != y) {
if (z == -1) {
z = i;
} else {
w = i;
break;
}
}
}
int r = query(x, z);
if (r) {
r = query(x, w);
if (r) {
return 2; // star
} else {
return 1; // chain
}
} else {
r = query(y, z);
}
if (r) {
r = query(y, w);
if (r) {
return 2; // star
} else {
return 1; // chain
}
} else {
return 1; // chain
}
return 1;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
int u = -1, v = -1;
for (int i = 1; i < n; i+=2) {
int r = query(i, i+1);
if (r) {
u = i;
v = i+1;
break;
}
}
if (n & 2 && u == -1) {
int r = query(n-1, n);
if (r) {
u = n-1;
v = n;
}
}
if (u == -1) {
answer(1); // chain
} else {
answer(solve(u, v));
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3812kb
input:
2 4 1 0 1 0 4 0 1 1 1
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ! 1 ? 1 2 ? 3 4 ? 3 1 ? 3 2 ! 2
result:
ok Correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3884kb
input:
87 13 0 0 0 0 0 1 0 1 1 15 0 0 0 0 0 0 1 1 1 7 0 0 0 1 0 1 1 15 0 0 0 1 0 0 19 0 0 0 0 0 1 1 1 20 0 0 0 0 0 0 0 0 0 0 7 0 0 1 0 1 1 20 0 0 0 0 0 0 0 1 1 1 17 0 0 0 0 0 0 0 0 11 1 0 0 14 0 0 0 0 0 0 0 0 13 0 0 0 0 0 0 18 0 0 0 0 0 1 0 1 1 14 0 1 0 1 1 20 0 0 0 0 1 0 0 11 0 0 0 1 0 0 11 0 1 0 0 8 0 1 ...
output:
? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 11 1 ? 12 1 ? 12 2 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 13 14 ? 13 1 ? 13 2 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 6 7 ? 6 1 ? 7 1 ? 7 2 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 7 1 ? 8 1 ! 1 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 11 1 ? 11 2 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 ...
result:
wrong answer Wrong prediction (test case 26)