#6456. CSP-J初赛真题2019年
CSP-J初赛真题2019年
一、单项选择题(共 15 题,每题 2 分,共计 30 分)
- 中国的国家顶级域名是()。 {{ select(1) }}
- .cn
- .ch
- .chn
- .china
- 二进制数 11101110010111 和 01011011101011 进行逻辑与运算的结果是()。 {{ select(2) }}
- 01001010001011
- 01001010010011
- 01001010000001
- 01001010000011
- 一个 32 位整型变量占用()个字节。 {{ select(3) }}
- 32
- 128
- 4
- 8
- 若有如下程序段,其中 s、a、b、c 均已定义为整型变量,且 a、c 均已赋值(c 大于 0)
s = a;
for (b = 1; b <= c; b++) s = s - 1;
则与上述程序段功能等价的赋值语句是()。 {{ select(4) }}
- s = a - c
- s = a - b
- s = s - c
- s = b - c
- 设有 100 个已排好序的数据元素,采用折半查找时,最大比较次数为()。 {{ select(5) }}
- 7
- 10
- 6
- 8
- 链表不具有的特点是()。 {{ select(6) }}
- 插入删除不需要移动元素
- 不必事先估计存储空间
- 所需空间与线性表长度成正比
- 可随机访问任一元素
- 把 8 个同样的球放在 5 个同样的袋子里,允许有的袋子空着不放,共有多少种不同的分法?() {{ select(7) }}
- 22
- 24
- 18
- 20
- 一棵二叉树采用顺序存储,根下标为 1,若下标为 i 的结点左孩子 2i、右孩子 2i+1,则该数组最大下标至少为()。 {{ select(8) }}
- 6
- 10
- 15
- 12
- 100 以内最大的素数是()。 {{ select(9) }}
- 89
- 97
- 91
- 93
- 319 和 377 的最大公约数是()。 {{ select(10) }}
- 27
- 33
- 29
- 31
- 小胖每周跑步,最多可以消耗多少千卡?(周一到周四半小时跑 3 公里,周五到周日一小时跑 5 公里,每周最多 21 公里) {{ select(11) }}
- 3000
- 2500
- 2400
- 2520
- 从 52 张牌中随机抽取 13 张,则至少()张牌的花色一致。 {{ select(12) }}
- 4
- 2
- 3
- 5
- 5 位车牌,倒过来还是原来的车牌,最多有()个。(0、1、8 不变,6 和 9 互换) {{ select(13) }}
- 60
- 125
- 75
- 100
- 一棵二叉树后序:DGJHEBIFCA,中序:DBGEHJACIF,则前序为()。 {{ select(14) }}
- ABCDEFGHIJ
- ABDEGHJCFI
- ABDEGJHCFI
- ABDEGHJFIC
- 计算机科学领域的最高奖是()。 {{ select(15) }}
- 图灵奖
- 鲁班奖
- 诺贝尔奖
- 普利策奖
二、阅读程序(判断题 1.5 分,选择题 4 分,共计 40 分)
程序一
#include <cstdio>
#include <cstring>
using namespace std;
char st[100];
int main(){
scanf("%s", st);
int n = strlen(st);
for(int i = 1; i <= n; ++i){
if(n % i == 0){
char c = st[i - 1];
if (c >= 'a')
st[i-1] = c - 'a' + 'A';
}
}
printf("%s", st);
return 0;
}
- 输入的字符串只能由小写字母或大写字母组成。() {{ select(16) }}
- 对
- 错
- 若将第 8 行的
i = 1改为i = 0,程序运行时会发生错误。() {{ select(17) }}
- 对
- 错
- 若将第 8 行的
i <= n改为i * i <= n,程序运行结果不会改变。() {{ select(18) }}
- 对
- 错
- 若输入的字符串全部由大写字母组成,那么输出的字符串就跟输入的字符串一样。() {{ select(19) }}
- 对
- 错
- 若输入的字符串长度为 18,那么输入与输出相比,至多有()个字符不同。 {{ select(20) }}
- 18
- 6
- 10
- 1
- 若输入的字符串长度为(),那么输入与输出相比,至多有 36 个字符不同。 {{ select(21) }}
- 36
- 100000
- 1
- 128
程序二
#include <cstdio>
using namespace std;
int n, m;
int a[100], b[100];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i)
a[i] = b[i] = 0;
for (int i = 1; i <= m; ++i) {
int x, y;
scanf("%d%d", &x, &y);
if (a[x] < y && b[y] < x) {
if (a[x] > 0)
b[a[x]] = 0;
if (b[y] > 0)
a[b[y]] = 0;
a[x] = y;
b[y] = x;
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] != 0)
++ans;
if (b[i] != 0)
++ans;
}
printf("%d\n", ans);
return 0;
}
- 当 m>0 时,输出的值一定小于 2n。() {{ select(22) }}
- 对
- 错
- 执行完第 27 行的
++ans时,ans 一定是偶数。() {{ select(23) }}
- 对
- 错
- a[i] 和 b[i] 不可能同时大于 0。() {{ select(24) }}
- 对
- 错
- 若程序执行到第 13 行时,x 总是小于 y,那么第 15 行不会被执行。() {{ select(25) }}
- 对
- 错
- 若 m 个 x 两两不同,且 m 个 y 两两不同,则输出的值为() {{ select(26) }}
- 2n-2m
- 2n+2
- 2n-2
- 2n
- 若 m 个 x 两两不同,且 m 个 y 都相等,则输出的值为() {{ select(27) }}
- 2n-2
- 2n
- 2m
- 2n-2m
程序三
#include <iostream>
using namespace std;
const int maxn = 10000;
int n;
int a[maxn], b[maxn];
int f(int l, int r, int depth) {
if (l > r) return 0;
int min = maxn, mink;
for (int i = l; i <= r; ++i) {
if (min > a[i]) {
min = a[i];
mink = i;
}
}
int lres = f(l, mink - 1, depth + 1);
int rres = f(mink + 1, r, depth + 1);
return lres + rres + depth * b[mink];
}
int main() {
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n; ++i) cin >> b[i];
cout << f(0, n - 1, 1) << endl;
return 0;
}
- 如果 a 数组有重复的数字,则程序运行时会发生错误。() {{ select(28) }}
- 对
- 错
- 如果 b 数组全为 0,则输出为 0。() {{ select(29) }}
- 对
- 错
- 当 n=100 时,最坏情况下,与第 12 行的比较运算执行的次数最接近的是()。 {{ select(30) }}
- 5000
- 600
- 6
- 100
- 当 n=100 时,最好情况下,与第 12 行的比较运算执行的次数最接近的是()。 {{ select(31) }}
- 100
- 6
- 5000
- 600
- 当 n=10 时,若 b[i] = i + 1,输出最大为()。 {{ select(32) }}
- 386
- 383
- 384
- 385
- 当 n=100 时,若 b[i]=1,输出最小为()。 {{ select(33) }}
- 582
- 580
- 579
- 581
三、完善程序(单选题,每题 3 分,共计 30 分)
程序一(矩阵变幻)
#include <cstdio>
using namespace std;
int n;
const int max_size = 1 << 10;
int res[max_size][max_size];
void recursive(int x, int y, int n, int t) {
if (n == 0) {
res[x][y] = ①;
return;
}
int step = 1 << (n - 1);
recursive(②, n - 1, t);
recursive(x, y + step, n - 1, t);
recursive(x + step, y, n - 1, t);
recursive(③, n - 1, !t);
}
int main() {
scanf("%d", &n);
recursive(0, 0, ④);
int size = ⑤;
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++)
printf("%d ", res[i][j]);
puts("");
}
return 0;
}
- ①处应填() {{ select(34) }}
- n % 2
- 0
- t
- 1
- ②处应填() {{ select(35) }}
- x – step, y – step
- x,y - step
- x – step, y
- x, y
- ③处应填() {{ select(36) }}
- x - step, y - step
- x + step, y + step
- x - step, y
- x, y – step
- ④处应填() {{ select(37) }}
- n - 1, n % 2
- n, 0
- n, n % 2
- n - 1, 0
- ⑤处应填() {{ select(38) }}
- 1 << (n + 1)
- 1 << n
- n + 1
- 1 << (n - 1)
程序二(基数排序)
// 基数排序(简化版)
const int maxs = 1000;
int a[1005], b[1005];
int cnt[1005], ord[1005], res[1005];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
// 按第二关键字排序
for (int i = 0; i < n; i++) ①;
for (int i = 0; i < n; i++) ②;
// 按第一关键字排序
for (int i = 0; i < n; i++) ③;
for (int i = 0; i < n; i++) ④;
for (int i = 0; i < n; i++)
cout << ⑤ << endl;
}
- ①处应填() {{ select(39) }}
- ++cnt[i]
- ++cnt[b[i]]
- ++cnt[a[i] * maxs + b[i]]
- ++cnt[a[i]]
- ②处应填() {{ select(40) }}
- ord[--cnt[a[i]]] = i
- ord[--cnt[b[i]]] = a[i]
- ord[--cnt[a[i]]] = b[i]
- ord[--cnt[b[i]]] = i
- ③处应填() {{ select(41) }}
- ++cnt[b[i]]
- ++cnt[a[i] * maxs + b[i]]
- ++cnt[a[i]]
- ++cnt[i]
- ④处应填() {{ select(42) }}
- res[--cnt[a[ord[i]]]] = ord[i]
- res[--cnt[b[ord[i]]]] = ord[i]
- res[--cnt[b[i]]] = ord[i]
- res[--cnt[a[i]]] = ord[i]
- ⑤处应填() {{ select(43) }}
- a[i], b[i]
- a[res[i]], b[res[i]]
- a[ord[res[i]]], b[ord[res[i]]]
- a[res[ord[i]]], b[res[ord[i]]]