#2567. 2024 CSP-S1 真题 · 阅读程序1

2024 CSP-S1 真题 · 阅读程序1

2024 CSP-S1 真题(120 分钟,总分 100 分)

阅读程序1(共 5 题,共 11.5 分)

1.

#include <iostream>
using namespace std;

const int N = 1000;
int c[N];

int logic(int x, int y) {
    return (x & y) ^ ((x ^ y) | (~x & y));
}
void generate(int a, int b, int *c) {
    for (int i = 0; i < b; i++) {
        c[i] = logic(a, i) % (b + 1);
    }
}
void recursion(int depth, int *arr, int size) {
    if (depth <= 0 || size <= 1) return;
    int pivot = arr[0];
    int i = 0, j = size - 1;
    while (i <= j) {
        while (arr[i] < pivot) i++;
        while (arr[j] > pivot) j--;
        if (i <= j) {
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
            i++; j--;
        }
    }
    recursion(depth - 1, arr, j + 1);
    recursion(depth - 1, arr + i, size - i);
}

int main() {
    int a, b, d;
    cin >> a >> b >> d;
    generate(a, b, c);
    recursion(d, c, b);
    for (int i = 0; i < b; ++i) cout << c[i] << " ";
}
    cout << endl;
}

当1000≥d≥b时,输出的序列是有序的。

{{ select(1) }}

  • 正确
  • 错误

2. 当输入"551"时,输出为"11555"。

{{ select(2) }}

  • 正确
  • 错误

3. 假设数组c长度无限制,该程序所实现的算法的时间复杂度是O(b)的。

{{ select(3) }}

  • 正确
  • 错误

4. 函数int logic(intx,inty)的功能是

{{ select(4) }}

  • 按位与
  • 按位或
  • 按位异或
  • 以上都不是

5. 当输入为"10 100 100"时,输出的第100个数是

{{ select(5) }}

  • 91
  • 94
  • 95
  • 98