QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#613069#8239. Mysterious TreemojimoonWA 1ms3864kbC++141.9kb2024-10-05 13:31:312024-10-05 13:31:32

Judging History

你现在查看的是最新测评结果

  • [2024-10-05 13:31:32]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3864kb
  • [2024-10-05 13:31:31]
  • 提交

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
*/

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        scanf("%d", &n);
        int u = -1, v = -1, r;
        for (int i = 1; i < n; i+= 2) {
            printf("? %d %d\n", i, i + 1);
            fflush(stdout);
            scanf("%d", &r);
            if (r == 1) {
                u = i;
                v = i + 1;
                break;
            }
        }

        if (r == 0) {
            printf("! 2\n"); // chain
            fflush(stdout);
            continue;
        }

        int p1 = -1, p2 = -1;
        // choose 2 arbitrary nodes other than u and v
        for (int i = 1; i <= n; i++) {
            if (i != u && i != v) {
                if (p1 == -1) {
                    p1 = i;
                } else {
                    p2 = i;
                    break;
                }
            }
        }

        int r1, r2;
        printf("? %d %d\n", p1, u);
        fflush(stdout);
        scanf("%d", &r1);
        printf("? %d %d\n", p1, v);
        fflush(stdout);
        scanf("%d", &r2);

        if (!r1 && !r2) {
            printf("! 2\n"); // chain
            fflush(stdout);
        } else {
            if (r2) {
                swap(u, v);
            }
            printf("? %d %d\n", p2, u);
            fflush(stdout);
            scanf("%d", &r1);
            if (r1) {
                printf("! 1\n"); // star
                fflush(stdout);
            } else {
                printf("! 2\n"); // chain
                fflush(stdout);
            }
        }
    }
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3864kb

input:

2
4
1
0
1
0

output:

? 1 2
? 3 1
? 3 2
? 4 2
! 2

result:

wrong answer Wrong prediction (test case 1)