#CCF2021J. 2021 入门级第一轮

2021 入门级第一轮

一、单项选择题(共15题,每题2分,共计30分;每题有且仅有一个正确选项)

  1. 以下不属于面向对象程序设计语言的是( )。 {{ select(1) }}
  • C++
  • Python
  • Java
  • C
  1. 以下奖项与计算机领域最相关的是( )。 {{ select(2) }}
  • 奥斯卡奖
  • 图灵奖
  • 诺贝尔奖
  • 普利策奖
  1. 目前主流的计算机储存数据最终都是转换成( )数据进行储存。 {{ select(3) }}
  • 二进制
  • 十进制
  • 八进制
  • 十六进制
  1. 以比较作为基本运算,在 𝑁𝑁 个数中找出最大数,最坏情况下所需要的最少的比较次数为 ( )。 {{ select(4) }}
  • N2N^2
  • NN
  • N1N-1
  • N+1N+1
  1. 对于入栈顺序为 a,b,c,d,ea,b,c,d,e 的序列,下列( )不是合法的出栈序列。 {{ select(5) }}
  • a,b,c,e,da,b,c,e,d
  • e,d,c,b,ae,d,c,b,a
  • b,a,c,d,eb,a,c,d,e
  • c,d,a,e,bc,d,a,e,b
  1. 对于有 𝑛𝑛 个顶点、𝑚𝑚 条边的无向连通图 (𝑚>𝑛)(𝑚>𝑛),需要删掉( )条边才能使其成为一棵树。 {{ select(6) }}
  • n1n-1
  • mnm-n
  • mn1m-n-1
  • mn+1m-n+1
  1. 二进制数 101.11 对应的十进制数是( )。 {{ select(7) }}
  • 6.5
  • 5.5
  • 5.75
  • 5.25
  1. 如果一棵二叉树只有根结点,那么这棵二叉树高度为 1。请问高度为 5 的完全二叉树有 ( )种不同的形态?

    {{ select(8) }}

  • 16
  • 15
  • 17
  • 32
  1. 表达式 a*(b+c)*d 的后缀表达式为( ),其中 *+ 是运算符。 {{ select(9) }}
  • **a+bcd
  • abc+*d*
  • abc+d**
  • *a*+bcd
  1. 6 个人,两个人组一队,总共组成三队,不区分队伍的编号。不同的组队情况有( )种。 {{ select(10) }}
  • 10
  • 15
  • 30
  • 20
  1. 在数据压缩编码中的哈夫曼编码方法,在本质上是一种( )的策略。 {{ select(11) }}
  • 枚举
  • 贪心
  • 递归
  • 动态规划
  1. 由 1,1,2,2,3这五个数字组成不同的三位数有( )种。

    {{ select(12) }}

  • 18
  • 15
  • 12
  • 24
  1. 考虑如下递归算法
solve(n)  
     if n<=1 return 1  
      else if n>=5 return n*solve(n-2)  
      else return n*solve(n-1)

则调用 solve(7) 得到的返回结果为( )。 {{ select(13) }}

  • 105
  • 840
  • 210
  • 420
  1. 𝑎𝑎 为起点,对下边的无向图进行深度优先遍历,则 𝑏,𝑐,𝑑,𝑒𝑏,𝑐,𝑑,𝑒四个点中有可能作为最后一个遍历到的点的个数为( )。

alt {{ select(14) }}

  • 1
  • 2
  • 3
  • 4
  1. 有四个人要从 AA 点坐一条船过河到 BB 点,船一开始在 AA 点。该船一次最多可坐两个人。 已知这四个人中每个人独自坐船的过河时间分别为 1,2,4,8,且两个人坐船的过河时间为两人独自过河时间的较大者。则最短( )时间可以让四个人都过河到 BB 点(包括从 BB 点把船开回 AA 点的时间)。 {{ select(15) }}
  • 14
  • 15
  • 16
  • 17

二、阅读程序(程序输入不超过数组或字符串定义的范围;判断题正确填 √,错误填 ×;除特殊说明外,判断题 1.5 分,选择题 3分,共计 40分)

1.

1 	#include <stdio.h>
2 
3 	int n;
4 	int a[1000];
5 
6 	int f(int x)
7 	{                               
8 		int ret = 0;
9 		for (; x; x &= x - 1) ret++;    
10		return ret;
11	}                   		       
12
13	int g(int x)
14	{
15		return x & -x; 
16	}         		                   
17
18	int main()
19	{
20		scanf("%d", &n);
21		for (int i = 0; i < n; i++) scanf("%d", &a[i]);
22		for (int i = 0; i < n; i++)
23			printf("%d ", f(a[i]) + g(a[i]));
24		printf("\n");
25		return 0;
26	}
27
  • 判断题
  1. 输入的𝑛𝑛等于1001时,程序不会发生下标越界。() {{ select(16) }}
  • 正确
  • 错误
  1. 输入的 𝑎[𝑖] 必须全为正整数,否则程序将陷入死循环。() {{ select(17) }}
  • 正确
  • 错误
  1. 当输入为”5 2 11 9 16 10”时,输出为”3 4 3 17 5”。() {{ select(18) }}
  • 正确
  • 错误
  1. 当输入为”1 511998”时,输出为”18” 。() {{ select(19) }}
  • 正确
  • 错误
  1. 将源代码中𝑔函数的定义(13-16行)移到𝑚𝑎𝑖𝑛函数的后面,程序可以正常编译运行。() {{ select(20) }}
  • 正确
  • 错误
  • 选择题
  1. 当输入为”2 -65536 2147483647”时,输出为() {{ select(21) }}
  • 65532 33
  • 65552 32
  • 65535 34
  • 65554 33

2.

1 	#include <stdio.h>
2 	#include <string.h>
3 
4 	char base[64];
5 	char table[256];
6 	char str[256];
7 	char ans[256];
8 
9 	void init()
10	{
11		for (int i = 0; i < 26; i++) base[i] = 'A' + i;
12		for (int i = 0; i < 26; i++) base[26 + i] = 'a' + i;
13		for (int i = 0; i < 10; i++) base[52 + i] = '0' + i;
14		base[62] = '+', base[63] = '/';
15
16		for (int i = 0; i < 256; i++) table[i] = 0xff;
17		for (int i = 0; i < 64; i++) table[base[i]] = i;
18		table['='] = 0;
19	}
20
21	void decode(char *str)
22	{
23		char *ret = ans;
24		int i, len = strlen(str);
25		for (i = 0; i < len; i += 4) {
26			(*ret++) = table[str[i]] << 2 | table[str[i + 1]] >> 4;
27			if (str[i + 2] != '=')
28				(*ret++) = (table[str[i + 1]] & 0x0f) << 4 | table[str[i + 2]] >> 2;
29			if(str[i + 3] != '=')
30				(*ret++) = table[str[i + 2]] << 6 | table[str[i + 3]];
31		}
32	}
33
34	int main()
35	{
36		init();
37		printf("%d\n", (int)table[0]);
38
39		scanf("%s", str);
40		decode(str);
41		printf("%s\n", ans);
42		return 0;
43	}
  • 判断题
  1. 输出的第二行一定是由小写字母、大写字母、数字和”+”、”/”、”=”构成的字符串。() {{ select(22) }}
  • 正确
  • 错误
  1. 可能存在输入不同,但输出的第二行相同的情形。() {{ select(23) }}
  • 正确
  • 错误
  1. 输出的第一行为”-1”。() {{ select(24) }}
  • 正确
  • 错误
  • 单选题
  1. 设输入字符串长度为𝑛𝑛,𝑑𝑒𝑐𝑜𝑑𝑒函数的时间复杂度为() {{ select(25) }}
  • O(n)O\sqrt(n)
  • O(n)O(n)
  • O(nlgn)O(nlg^n)
  • O(n2)O(n^2)
  1. 当输入为”Y3Nx”时,输出的第二行为() {{ select(26) }}
  • csp
  • csq
  • CSP
  • Csp
  1. 当输入为”Y2NmIDIwMjE=”时,输出的第二行为() {{ select(27) }}
  • ccf2021
  • ccf2022
  • ccf 2021
  • ccf 2022

3.

1 	#include <stdio.h>
2 
3 	#define n 100000
4 	#define	N n+1
5 
6 	int m;
7 	int a[N], b[N], c[N], d[N];
8 	int f[N], g[N];
9 
10	void init() 
11	{
12		f[1] = g[1] = 1;
13		for (int i = 2; i <= n; i++) {
14			if (!a[i]) {
15				b[m++] = i;
16				c[i] = 1, f[i] = 2;
17				d[i] = 1, g[i] = i + 1;
18			}
19			for (int j = 0; j < m && b[j] * i <= n; j++) {
20				int k = b[j];
21				a[i * k] = 1;
22				if (i % k == 0) {
23					c[i * k] = c[i] + 1;
24					f[i * k] = f[i] / c[i * k] * (c[i * k] + 1);
25					d[i * k] = d[i];
26					g[i * k] = g[i] * k + d[i];
27					break;
28				}
29				else {
30					c[i * k] = 1;
31					f[i * k] = 2 * f[i];
32					d[i * k] = g[i];
33					g[i * k] = g[i] * (k + 1);
34				}
35			}
36		}
37	}
38
39	int main() 
40	{
41		init();
42		
43		int x;
44		scanf("%d", &x);
45		printf("%d %d\n", f[x], g[x]);
46		return 0;
47	}

假设输入的𝑥𝑥是不超过1000的自然数,完成下面的判断题和单选题:

  • 判断题
  1. 若输入不为”1”,把第12行删去不会影响输出的结果。() {{ select(28) }}
  • 正确
  • 错误
  1. 第24行f[i * k] = f[i] / c[i * k] * (c[i * k] + 1)中的” f[i]/c[i*k]”可能存在无法整除而向下取整的情况。() {{ select(29) }}
  • 正确
  • 错误
  1. 在执行完𝑖𝑛𝑖𝑡()后,f数组不是单调递增的,但𝑔数组是单调递增的。() {{ select(30) }}
  • 正确
  • 错误
  • 选择题
  1. init函数的时间复杂度为()。 {{ select(31) }}
  • O(n)O(n)
  • O(nlgn)O(nlg^n)
  • O(nn)O(n \sqrt n)
  • O(n2)O(n^2)
  1. 在执行完𝑖𝑛𝑖𝑡()𝑓[1],𝑓[2],𝑓[3]......𝑓[100]中有()个等于2。 {{ select(32) }}
  • 23
  • 24
  • 25
  • 26
  1. (4分)当输入”1000”时,输出为()。 {{ select(33) }}
  • 15 1340
  • 15 2340
  • 16 2340
  • 16 1340

三、完善程序(单选题,每小题3分,共计30分)

1.(Josephus 问题)有 𝑛𝑛 个人围成一个圈,依次标号 0 至 𝑛1𝑛−1。从 0 号开始,依次 0, 1, 0, 1, ... 交替报数,报到 1 的人会离开,直至圈中只剩下一个人。求最后剩下人的编号。 试补全模拟程序。

1 	#include <stdio.h>
2 
3 	const int MAXN = 1000000;
4 	int F[MAXN];
5 
6 	int main(){
7 		int n;
8 		scanf("%d", &n);
9 		int i = 0, p = 0, c = 0;
10		while( ①){
11			if (F[i] == 0){
12				if ( ② ){
13					F[i] = 1;
14					③; 
15				}
16				④; 
17			}
18			⑤; 
19		} 
20		int ans = -1;
21		for (int i = 0; i < n; i++)
22			if (F[i] == 0)
23				ans = i;
24		printf("%d\n", ans);
25		return 0;
26	}
  1. ①处应填() {{ select(34) }}
  • i<n
  • c<n
  • i<n-1
  • c<n-1
  1. ②处应填() {{ select(35) }}
  • i%2==0
  • i%2==1
  • p
  • !p
  1. ③处应填() {{ select(36) }}
  • i++
  • i=(i+1)%n
  • c++
  • p^=1
  1. ④处应填() {{ select(37) }}
  • i++
  • i=(i+1)%n
  • c++
  • p^=1
  1. ⑤处应填() {{ select(38) }}
  • i++
  • i=(i+1)%n
  • c++
  • p^=1

2.(矩形计数)平面上有𝑛𝑛个关键点,求有多少个四条边都和𝑥𝑥轴或者𝑦𝑦轴平行的矩形,满足四个顶点都是关键点。给出的关键点可能有重复,但完全重合的矩形只计一次。 试补全枚举算法。

1 	#include <stdio.h>
2 
3 	struct point {
4 		int x, y, id;
5 	};
6 
7 	int equals(struct point a, struct point b){
8 		return a.x == b.x && a.y == b.y;
9 	}
10
11	int cmp(struct point a, struct point b){
12		return  ①; 
13	}
14
15	void sort(struct point A[], int n){
16		for (int i = 0; i < n; i++)
17			for (int j = 1; j < n; j++)
18				if (cmp(A[j], A[j - 1])){
19					struct point t = A[j];
20					A[j] = A[j - 1];
21					A[j - 1] = t;
22				}
23	}
24
25	int unique(struct point A[], int n){
26		int t = 0;
27		for (int i = 0; i < n; i++)
28			if (②)
29				A[t++] = A[i];
30		return t;
31	}
32
33	int binary_search(struct point A[], int n, int x, int y){
34		struct point p;
35		p.x = x;
36		p.y = y;
37		p.id = n;
38		int a = 0, b = n - 1;
39		while(a < b){
40			int mid = ③;
41			if (④)
42				a = mid + 1;
43			else 
44				b = mid; 
45		}
46			return equals(A[a], p);
47	}
48
49	#define MAXN 1000
50	struct point A[MAXN];
51
52	int main(){
53		int n;
54		scanf("%d", &n);
55		for (int i = 0; i < n; i++){
56			scanf("%d %d", &A[i].x, &A[i].y);
57			A[i].id = i;
58		}
59		sort(A, n);
60		n = unique(A, n);
61		int ans = 0;
62		for (int i = 0; i < n; i++)
63			for (int j = 0; j < n; j++)
64			if ( ⑤ && binary_search(A, n, A[i].x, A[j].y) && binary_search(A, n, A[j].x, A[i].y)){
65							ans++;
66			}
67		printf("%d\n", ans); 
68		return 0;
69	}
  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)
  1. ②处应填() {{ 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])
  1. ③处应填() {{ select(41) }}
  • b - (b - a) / 2 + 1
  • (a + b + 1) >> 1
  • (a + b) >> 1
  • a + (b - a + 1) / 2
  1. ④处应填() {{ select(42) }}
  • !cmp(A[mid], p)
  • cmp(A[mid], p)
  • cmp(p, A[mid])
  • !cmp(p, A[mid])
  1. ⑤处应填() {{ 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