B. 372. 2023年粤港澳大赛初赛(阅读代码题)

    客观题

372. 2023年粤港澳大赛初赛(阅读代码题)

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

阅读代码题

第一道

#include <iostream>
using namespace std;
int a, b, c;
int main() {
  cin >> a >> b >> c;
  int t = b;
  b = a, a = t;
  c = a;
  cout << a << " " << b << " " << c;
}
  1. 若输入 391391,则输出 933933

{{ select(16) }}

  • 正确
  • 错误
  1. 若输入 12300400000 3 7,将⼀定能输出 3 12300400000 3。( )

{{ select(17) }}

  • 正确
  • 错误
  1. 该程序中,头文件 #include <iostream> 可以改成 #include <cstdio>。( )

{{ select(18) }}

  • 正确
  • 错误
  1. 若输入 3 6 9,输出( )。 {{ select(19) }}
  • 6 3 6
  • 9 3 3
  • 6 9 3
  • 6 3 3
  1. 若将 c=a 改成 c=t,则输入 3 6 9,输出( )。

{{ select(20) }}

  • 6 3 6
  • 9 3 3
  • 6 9 3
  • 6 3 3
  1. 若将 c=a 改成 c=b,则输入 3 6 9,输出( )。

{{ select(21) }}

  • 6 3 6
  • 9 3 3
  • 6 9 3
  • 6 3 3

第二道

#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int w[35000], d[35000], dp[35000];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &w[i], &d[i]);
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= w[i]; j--) {
      dp[j] = max(dp[j], dp[j - w[i]] + d[i]); 
    }
  }
  printf("%d\n", dp[m]);
  return 0;
}
  1. 上述代码中,双重循环里循环变量 j 的枚举顺序改为从 w[i]m,输出结果一定不变( )。

{{ select(22) }}

  • 正确
  • 错误
  1. 上述代码中,双重循环中循环变量 i 的枚举顺序从 n1,输出结果一定不变( )。

{{ select(23) }}

  • 正确
  • 错误
  1. 若输入数据中,1n,m,w[i],d[i]300001 \le n,m,w[i],d[i] \le 30000,则所求答案一定没有溢出。( )

{{ select(24) }}

  • 正确
  • 错误
  1. m 等于所有 w[i] 的和的时候,输出结果为( )。

{{ select(25) }}

  • 所有 d[i] 的和
  • 最大的 d[i] 值的 nn
  • 最大的 d[i] 值的 mm
  • nmnm
  1. 当输入为
4 6
1 4
2 6
3 12
2 7

输出为( )

{{ select(26) }}

  • 17
  • 28
  • 29
  • 23
  1. 上述代码时间复杂度为( )。

{{ select(27) }}

  • O(N)\mathcal{O}(N)
  • O(N2×M)\mathcal{O}(N^2 \times M)
  • O(N×M)\mathcal{O}(N \times M)
  • O(N×M2)\mathcal{O}(N \times M^2)

第三题

#include <iostream>
#include <cstring>
#include <cstdio>
#define N 500+10
using namespace std;
int a[N], n;
int main()
{
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++)
  {
    int tmp = i;
    for (int j = i + 1; j <= n; j++)
      if (a[j] < a[tmp]) tmp = j;
    swap(a[i], a[tmp]);
  }
  for (int i = 1; i <= n; i++) cout << a[i] << " ";
  cout << endl;
  return 0;
}
  1. 上述代码实现了对一个长度为 nn 的序列进行排序。( )

{{ select(28) }}

  • 正确
  • 错误
  1. 去掉头文件 #include <cstdio> 后程序仍能正常编译运行。( )

{{ select(29) }}

  • 正确
  • 错误
  1. 去掉 using namespace std; 后程序仍能正常编译运行。( )

{{ select(30) }}

  • 正确
  • 错误
  1. 我们将上述算法称为( )。

{{ select(31) }}

  • 插入排序
  • 冒泡排序
  • 选择排序
  • 归并排序
  1. 上述代码的时间复杂度为( )。

{{ select(32) }}

  • O(N)\mathcal{O}(N)
  • O(NlogN)\mathcal{O}(N \log N)
  • O(N2)\mathcal{O}(N^2)
  • O(N3)\mathcal{O}(N^3)
  1. 若输入数据为
5
3
2
1
5
4.

if(a[j] < a[tmp]) 这句话中的条件会成立( )次(即后面的 tmp=j 会执行多少次)。

{{ select(33) }}

  • 5
  • 7
  • 3
  • 4

粤港澳2023年初赛 - 小学组

未参加
状态
已结束
规则
IOI
题目
3
开始于
2025-5-3 9:00
结束于
2025-5-3 12:00
持续时间
3 小时
主持人
参赛人数
3