编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#20335 #5. 慢速排序/交互题测试 Accepted 100 791 ms 408 K C++ / 1.4 K 192022214033 2024-12-12 22:35:02
显示原始代码
#include <bits/stdc++.h>
using namespace std;

// 查询操作,返回隐藏数组中第 x 和第 y 元素的关系
char query(int x, int y) {
    cout << "c " << x << " " << y << endl;
    char response;
    cin >> response;
    return response;
}

// 交换操作,交换隐藏数组中第 x 和第 y 个元素
void swap_elements(int x, int y) { cout << "s " << x << " " << y << endl; }

// 完成操作,通知交互器完成
void finish() { cout << "e" << endl; }

int main() {
    int t;  // 测试组数
    cin >> t;
    while (t--) {
        int n;  // 当前测试组中数组的长度
        cin >> n;

        // 冒泡排序实现
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n - i; ++j) {
                // 比较相邻两个元素的大小
                if (query(j, j + 1) == '>') {
                    // 如果第 j 个元素大于第 j+1 个元素,则交换
                    swap_elements(j, j + 1);
                }
            }
        }

        // 通知交互器排序完成
        finish();

        // 检查交互器的响应是否正确
        char response;
        cin >> response;
        if (response != '1') {
            // 如果交互器返回的不是 '1',说明有错误
            cerr << "Sorting failed!" << endl;
            return 0;
        }
    }
    return 0;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:62 ms
内存:404 KiB

输入文件(1.in

1
100
743781 147215 632500 733399 151404 855564 158551 538029 58980 958050 361539 339637 566899 98
<599 bytes omitted>

Special Judge 信息

Congratulations! You did right job!
测试点 #2
Accepted
得分:100
用时:4 ms
内存:408 KiB

输入文件(2.in

1
3
1 2 3

Special Judge 信息

Congratulations! You did right job!
测试点 #3
Accepted
得分:100
用时:725 ms
内存:396 KiB

输入文件(3.in

1
300
743781 147215 632500 733399 151404 855564 158551 538029 58980 958050 361539 339637 566899 98
<1978 bytes omitted>

Special Judge 信息

Congratulations! You did right job!