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;
}
- 若输入 ,则输出 。
{{ select(16) }}
- 正确
- 错误
- 若输入
12300400000 3 7,将⼀定能输出3 12300400000 3。( )
{{ select(17) }}
- 正确
- 错误
- 该程序中,头文件
#include <iostream>可以改成#include <cstdio>。( )
{{ select(18) }}
- 正确
- 错误
- 若输入
3 6 9,输出( )。 {{ select(19) }}
6 3 69 3 36 9 36 3 3
- 若将
c=a改成c=t,则输入3 6 9,输出( )。
{{ select(20) }}
6 3 69 3 36 9 36 3 3
- 若将
c=a改成c=b,则输入3 6 9,输出( )。
{{ select(21) }}
6 3 69 3 36 9 36 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;
}
- 上述代码中,双重循环里循环变量
j的枚举顺序改为从w[i]到m,输出结果一定不变( )。
{{ select(22) }}
- 正确
- 错误
- 上述代码中,双重循环中循环变量
i的枚举顺序从n到1,输出结果一定不变( )。
{{ select(23) }}
- 正确
- 错误
- 若输入数据中,,则所求答案一定没有溢出。( )
{{ select(24) }}
- 正确
- 错误
- 当
m等于所有w[i]的和的时候,输出结果为( )。
{{ select(25) }}
- 所有
d[i]的和 - 最大的
d[i]值的 倍 - 最大的
d[i]值的 倍
- 当输入为
4 6
1 4
2 6
3 12
2 7
输出为( )
{{ select(26) }}
- 17
- 28
- 29
- 23
- 上述代码时间复杂度为( )。
{{ select(27) }}
第三题
#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;
}
- 上述代码实现了对一个长度为 的序列进行排序。( )
{{ select(28) }}
- 正确
- 错误
- 去掉头文件
#include <cstdio>后程序仍能正常编译运行。( )
{{ select(29) }}
- 正确
- 错误
- 去掉
using namespace std;后程序仍能正常编译运行。( )
{{ select(30) }}
- 正确
- 错误
- 我们将上述算法称为( )。
{{ select(31) }}
- 插入排序
- 冒泡排序
- 选择排序
- 归并排序
- 上述代码的时间复杂度为( )。
{{ select(32) }}
- 若输入数据为
5
3
2
1
5
4.
则 if(a[j] < a[tmp]) 这句话中的条件会成立( )次(即后面的 tmp=j 会执行多少次)。
{{ select(33) }}
- 5
- 7
- 3
- 4