一、单项选择题(1~15 题,每题 2 分,共 30 分)
- 以下不属于面向对象程序设计语言的是( )。
{{ select(1) }}
- 以下奖项与计算机领域最相关的是( )。
{{ select(2) }}
- 目前主流的计算机储存数据最终都是转换成( )数据进行储存。
{{ select(3) }}
- 以比较作为基本运算,在N 个数中找出最大数,最坏情况下所需要的最少的比较次数为( )。
{{ select(4) }}
- 对于入栈顺序为a, b, c, d, e 的序列,下列( )不是合法的出栈序列。
{{ select(5) }}
- a, b, c, d, e
- e, d, c, b, a
- b, a, c, d, e
- c, d, a, e, b
- 对于有n 个顶点、m 条边的无向连通图 (m>n),需要删掉( )条边才能使其成为一棵树。
{{ select(6) }}
- 二进制数101.11 对应的十进制数是( )。
{{ select(7) }}
- 如果一棵二叉树只有根结点,那么这棵二叉树高度为1。请问高度为5 的完全二叉树有( )种不同的形态?
{{ select(8) }}
- 表达式a*(b+c)d 的后缀表达式为( ),其中“”和“+”是运算符。
{{ select(9) }}
- **a+bcd
- abc+d
- abc+d**
- a+bcd
- 6 个人,两个人组一队,总共组成三队,不区分队伍的编号。不同的组队情况有( )种。
{{ select(10) }}
- 在数据压缩编码中的哈夫曼编码方法,在本质上是一种( )的策略。
{{ select(11) }}
- 由1,1,2,2,3 这五个数字组成不同的三位数有( )种。
{{ select(12) }}
- 考虑如下递归算法solve(n) if n<=1 return 1 else if n>=5 return nsolve(n-2) else return nsolve(n-1) 则调用solve(7)得到的返回结果为( )。
{{ select(13) }}
- 以a 为起点,对右边的无向图进行深度优先遍历,则b、 c、 d、 e 四个点中有可能作为最后一个遍历到的点的个数为( )。
{{ select(14) }}
- 有四个人要从A 点坐一条船过河到B 点,船一开始在A 点。该船一次最多可坐两个人。已知这四个人中每个人独自坐船的过河时间分别为1, 2, 4, 8, 且两个人坐船的过河时间为两人独自过河时间的较大者。则最短( )时间可以让四个人都过河到B 点(包括从 B 点把船开回A 点的时间)。
{{ select(15) }}
二、阅读程序(判断题正确填 √、错误填 ×;判断题每题 1.5 分,选择题每题 3 分)
程序 1
1 | #include <iostream>
2 | using namespace std;
3 | int n;
4 | int a[1000];
5 | int f(int x)
6 | {
7 | int ret = 0;
8 | for (; x; x &= x - 1) ret++;
9 | return ret;
10 | }
11 | int g(int x)
12 | {
13 | return x & -x;
14 | }
15 | int main()
16 | {
17 | cin >> n;
18 | for (int i = 0; i < n; i++) cin >> a[i];
19 | for (int i = 0; i < n; i++)
20 | cout << f(a[i]) + g(a[i]) << ' ';
21 | cout << endl;
22 | return 0;
23 | }
- 输入的n 等于1001 时,程序不会发生下标越界。( )
{{ select(16) }}
- 输入的a[i] 必须全为正整数,否则程序将陷入死循环。( )
{{ select(17) }}
- 当输入为“5 2 11 9 16 10”时,输出为“3 4 3 17 5”。( )
{{ select(18) }}
- 当输入为“1 511998”时,输出为“18”。( )
{{ select(19) }}
- 将源代码中g 函数的定义(14-17 行)移到main 函数的后面,程序可以正常编译运行。( )
{{ select(20) }}
程序 2
1 | #include <iostream>
2 | using namespace std;
3 | int n;
4 | int a[1000];
5 | int f(int x)
6 | {
7 | int ret = 0;
8 | for (; x; x &= x - 1) ret++;
9 | return ret;
10 | }
11 | int g(int x)
12 | {
13 | return x & -x;
14 | }
15 | int main()
16 | {
17 | cin >> n;
18 | for (int i = 0; i < n; i++) cin >> a[i];
19 | for (int i = 0; i < n; i++)
20 | cout << f(a[i]) + g(a[i]) << ' ';
21 | cout << endl;
22 | return 0;
23 | }
24 | #include <iostream>
25 | #include <string>
26 | using namespace std;
27 | char base[64];
28 | char table[256];
29 | void init()
30 | {
31 | for (int i = 0; i < 26; i++) base[i] = 'A' + i;
32 | for (int i = 0; i < 26; i++) base[26 + i] = 'a' + i;
33 | for (int i = 0; i < 10; i++) base[52 + i] = '0' + i;
34 | base[62] = '+', base[63] = '/';
35 | for (int i = 0; i < 256; i++) table[i] = 0xff;
36 | for (int i = 0; i < 64; i++) table[base[i]] = i;
37 | table['='] = 0;
38 | }
39 | string decode(string str)
40 | {
41 | string ret;
42 | int i;
43 | for (i = 0; i < str.size(); i += 4) {
44 | ret += table[str[i]] << 2 | table[str[i + 1]] >> 4;
45 | if (str[i + 2] != '=')
46 | ret += (table[str[i + 1]] & 0x0f) << 4 | table[str[i + 2]] >> 2;
47 | if (str[i + 3] != '=')
48 | ret += table[str[i + 2]] << 6 | table[str[i + 3]];
49 | }
50 | return ret;
51 | }
52 | int main()
53 | {
54 | init();
55 | cout << int(table[0]) << endl;
56 | string str;
57 | cin >> str;
58 | cout << decode(str) << endl;
59 | return 0;
60 | }
- 当输入为“2 -65536 2147483647”时,输出为( )。
{{ select(21) }}
- “65532 33”
- “65552 32”
- “65535 34”
- “65554 33”
- 输出的第二行一定是由小写字母、大写字母、数字和“+”、“/”、“=”构成的字符串。( )
{{ select(22) }}
- 可能存在输入不同,但输出的第二行相同的情形。( )
{{ select(23) }}
- 输出的第一行为“-1”。( )
{{ select(24) }}
- 设输入字符串长度为n,decode 函数的时间复杂度为( )。
{{ select(25) }}
- Θ(√n)
- Θ(n)
- Θ(nlog n)
- Θ(n2)
- 当输入为“Y3Nx”时,输出的第二行为( )。
{{ select(26) }}
程序 3
1 | #include <iostream>
2 | using namespace std;
3 | int n;
4 | int a[1000];
5 | int f(int x)
6 | {
7 | int ret = 0;
8 | for (; x; x &= x - 1) ret++;
9 | return ret;
10 | }
11 | int g(int x)
12 | {
13 | return x & -x;
14 | }
15 | int main()
16 | {
17 | cin >> n;
18 | for (int i = 0; i < n; i++) cin >> a[i];
19 | for (int i = 0; i < n; i++)
20 | cout << f(a[i]) + g(a[i]) << ' ';
21 | cout << endl;
22 | return 0;
23 | }
24 | #include <iostream>
25 | #include <string>
26 | using namespace std;
27 | char base[64];
28 | char table[256];
29 | void init()
30 | {
31 | for (int i = 0; i < 26; i++) base[i] = 'A' + i;
32 | for (int i = 0; i < 26; i++) base[26 + i] = 'a' + i;
33 | for (int i = 0; i < 10; i++) base[52 + i] = '0' + i;
34 | base[62] = '+', base[63] = '/';
35 | for (int i = 0; i < 256; i++) table[i] = 0xff;
36 | for (int i = 0; i < 64; i++) table[base[i]] = i;
37 | table['='] = 0;
38 | }
39 | string decode(string str)
40 | {
41 | string ret;
42 | int i;
43 | for (i = 0; i < str.size(); i += 4) {
44 | ret += table[str[i]] << 2 | table[str[i + 1]] >> 4;
45 | if (str[i + 2] != '=')
46 | ret += (table[str[i + 1]] & 0x0f) << 4 | table[str[i + 2]] >> 2;
47 | if (str[i + 3] != '=')
48 | ret += table[str[i + 2]] << 6 | table[str[i + 3]];
49 | }
50 | return ret;
51 | }
52 | int main()
53 | {
54 | init();
55 | cout << int(table[0]) << endl;
56 | string str;
57 | cin >> str;
58 | cout << decode(str) << endl;
59 | return 0;
60 | }
61 | #include <iostream>
62 | using namespace std;
63 | const int n = 100000;
64 | const int N = n + 1;
65 | int m;
66 | int a[N], b[N], c[N], d[N];
67 | int f[N], g[N];
68 | void init()
69 | {
70 | f[1] = g[1] = 1;
71 | for (int i = 2; i <= n; i++) {
72 | if (!a[i]) {
73 | b[m++] = i;
74 | c[i] = 1, f[i] = 2;
75 | d[i] = 1, g[i] = i + 1;
76 | }
77 | for (int j = 0; j < m && b[j] * i <= n; j++) {
78 | int k = b[j];
79 | a[i * k] = 1;
80 | if (i % k == 0) {
81 | c[i * k] = c[i] + 1;
82 | f[i * k] = f[i] / c[i * k] * (c[i * k] + 1);
83 | d[i * k] = d[i];
84 | g[i * k] = g[i] * k + d[i];
85 | break;
86 | }
87 | else {
88 | c[i * k] = 1;
89 | f[i * k] = 2 * f[i];
90 | d[i * k] = g[i];
91 | g[i * k] = g[i] * (k + 1);
92 | }
93 | }
94 | }
95 | }
96 | int main()
97 | {
98 | init();
99 | int x;
100 | cin >> x;
101 | cout << f[x] << ' ' << g[x] << endl;
102 | return 0;
103 | }
- (3.5 分)当输入为“Y2NmIDIwMjE=”时,输出的第二行为( )。
{{ select(27) }}
- “ccf2021”
- “ccf2022”
- “ccf 2021”
- “ccf 2022”
- 若输入不为“1”,把第13 行删去不会影响输出的结果。( )
{{ select(28) }}
- (2 分)第25 行的“f[i] / c[i * k]”可能存在无法整除而向下取整的情况。( )
{{ select(29) }}
- (2 分)在执行完init()后,f 数组不是单调递增的,但g 数组是单调递增的。( )
{{ select(30) }}
- init 函数的时间复杂度为( )。
{{ select(31) }}
- Θ(n)
- Θ(nlog n)
- Θ(n√n)
- Θ(n!)
- 在执行完init()后,f[1], f[2], f[3] …… f[100]中有( )个等于2。
{{ select(32) }}
- (4 分)当输入为“1000”时,输出为( )。
{{ select(33) }}
- “15 1340”
- “15 2340”
- “16 2340”
- “16 1340”
三、完善程序(每题 3 分)
程序 1
1 | #include <iostream>
2 | using namespace std;
3 | const int MAXN = 1000000;
4 | int F[MAXN];
5 | int main() {
6 | int n;
7 | cin >> n;
8 | int i = 0, p = 0, c = 0;
9 | while (①) {
10 | if (F[i] == 0) {
11 | if (②) {
12 | F[i] = 1;
13 | ③;
14 | }
15 | ④;
16 | }
17 | ⑤;
18 | }
19 | int ans = -1;
20 | for (i = 0; i < n; i++)
21 | if (F[i] == 0)
22 | ans = i;
23 | cout << ans << endl;
24 | return 0;
25 | }
- ①处应填( )
{{ select(34) }}
- i < n
- c < n
- i < n - 1
- c < n - 1
- ②处应填( )
{{ select(35) }}
- i % 2 == 0
- i % 2 == 1
- p
- !p
- ③处应填( )
{{ select(36) }}
- i++
- i = (i + 1) % n
- c++
- p ^= 1
- ④处应填( )
{{ select(37) }}
- i++
- i = (i + 1) % n
- c++
- p ^= 1
程序 2
1 | #include <iostream>
2 | using namespace std;
3 | const int MAXN = 1000000;
4 | int F[MAXN];
5 | int main() {
6 | int n;
7 | cin >> n;
8 | int i = 0, p = 0, c = 0;
9 | while (①) {
10 | if (F[i] == 0) {
11 | if (②) {
12 | F[i] = 1;
13 | ③;
14 | }
15 | ④;
16 | }
17 | ⑤;
18 | }
19 | int ans = -1;
20 | for (i = 0; i < n; i++)
21 | if (F[i] == 0)
22 | ans = i;
23 | cout << ans << endl;
24 | return 0;
25 | }
26 | #include <iostream>
27 | using namespace std;
28 | struct point {
29 | int x, y, id;
30 | };
31 | bool equals(point a, point b) {
32 | return a.x == b.x && a.y == b.y;
33 | }
34 | bool cmp(point a, point b) {
35 | return ①;
36 | }
37 | void sort(point A[], int n) {
38 | for (int i = 0; i < n; i++)
39 | for (int j = 1; j < n; j++)
40 | if (cmp(A[j], A[j - 1])) {
41 | point t = A[j];
42 | A[j] = A[j - 1];
43 | A[j - 1] = t;
44 | }
45 | }
46 | int unique(point A[], int n) {
47 | int t = 0;
48 | for (int i = 0; i < n; i++)
49 | if (②)
50 | A[t++] = A[i];
51 | return t;
52 | }
53 | bool binary_search(point A[], int n, int x, int y) {
54 | point p;
55 | p.x = x;
56 | p.y = y;
57 | p.id = n;
58 | int a = 0, b = n - 1;
59 | while (a < b) {
60 | int mid = ③;
61 | if (④)
62 | a = mid + 1;
63 | else
64 | b = mid;
65 | }
66 | return equals(A[a], p);
67 | }
68 | const int MAXN = 1000;
69 | point A[MAXN];
70 | int main() {
71 | int n;
72 | cin >> n;
73 | for (int i = 0; i < n; i++) {
74 | cin >> A[i].x >> A[i].y;
75 | A[i].id = i;
76 | }
77 | sort(A, n);
78 | n = unique(A, n);
79 | int ans = 0;
80 | for (int i = 0; i < n; i++)
81 | for (int j = 0; j < n; j++)
82 | if (⑤ && binary_search(A, n, A[i].x, A[j].y) && binary_search(A, n, A[j].x, A[i].y)) {
83 | ans++;
84 | }
85 | cout << ans << endl;
86 | return 0;
87 | }
- ⑤处应填( )
{{ select(38) }}
- i++
- i = (i + 1) % n
- c++
- p ^= 1
- ①处应填( )
{{ select(39) }}
- a.x != b.x ? a.x < b.x : a.id < b.id
- a.x != b.x ? a.x < b.x : a.y < b.y
- equals(a, b) ? a.id < b.id : a.x < b.x
- equals(a, b) ? a.id < b.id : (a.x != b.x ? a.x < b.x : a.y < b.y)
- ②处应填( )
{{ select(40) }}
- i == 0 || cmp(A[i], A[i - 1])
- t == 0 || equals(A[i], A[t - 1])
- i == 0 || !cmp(A[i], A[i - 1])
- t == 0 || !equals(A[i], A[t - 1])
- ③处应填( )
{{ select(41) }}
- b - (b - a) / 2 + 1
- (a + b + 1) >> 1
- (a + b) >> 1
- a + (b - a + 1) / 2
- ④处应填( )
{{ select(42) }}
- !cmp(A[mid], p)
- cmp(A[mid], p)
- cmp(p, A[mid])
- !cmp(p, A[mid])
- ⑤处应填( )
{{ select(43) }}
- A[i].x == A[j].x
- A[i].id < A[j].id
- A[i].x == A[j].x && A[i].id < A[j].id
- A[i].x < A[j].x && A[i].y < A[j].y