历年南京大学计算机保研上机真题
2025南京大学计算机保研上机真题
2024南京大学计算机保研上机真题
2023南京大学计算机保研上机真题
在线测评链接:https://pgcode.cn/school
Count Number of Binary Strings
题目描述
Given a positive integer n n n ( 3 ≤ n ≤ 90 3 \leq n \leq 90 3≤n≤90), count all possible distinct binary strings of length n n n such that there are no consecutive 1 1 1’s.
输入格式
A single integer n n n.
输出格式
A single integer representing the number of distinct binary strings of length n n n without consecutive 1 1 1’s.
输入样例
2
输出样例
3
Missing Number
题目描述
Given a positive integer n n n ( n ≤ 40 n \leq 40 n≤40), pick n − 1 n-1 n−1 numbers randomly from 1 1 1 to n n n and concatenate them in random order as a string s s s, which means there is a missing number between 1 1 1 and n n n. Can you find the missing number? (Notice that in some cases the answer will not be unique, and in these cases you only need to find one valid answer.)
输入格式
The input consists of two lines:
- The first line contains the integer n n n.
- The second line contains the string s s s formed by concatenating n − 1 n-1 n−1 numbers.
输出格式
Output the missing number.
输入样例
20
281971112205101569183132414117
输出样例
16
数字最小化问题
题目描述
给你一个不超过 100 的数 n n n,和一个不超过 100 的数字 k k k,要求从数 n n n中去掉 k k k个数字,然后使得去掉 k k k个数之后, n n n最小。
输入格式
输入包含两个整数 n n n和 k k k,其中 n n n和 k k k均不超过 100。
输出格式
输出去掉 k k k个数字后得到的最小数字。
输入样例
1432219 3
输出样例
1219
删除数字使剩余数最小
题目描述
给你一个不超过 100 位的数 n n n,和一个不超过 100 的数字 k k k,要求从数 n n n中去掉 k k k个数字,然后使得去掉 k k k个数字之后, n n n最小。
输入格式
输入包含两个部分:
-
第一行是一个不超过 100 位的数 n n n。
-
第二行是一个不超过 100 的数字 k k k。
输出格式
输出去掉 k k k个数字后得到的最小的数 n n n。
输入样例
1432219
3
输出样例
1219
排队排列问题
题目描述
有 B B B个男孩, G G G个女孩,要求所有男孩女孩排成一队,连续的男孩个数不可以超过 K K K个,问一共有多少种排法。
(结果需要 m o d 10007 mod\ 10007 mod 10007)
输入格式
输入包含三个整数 B B B, G G G, K K K,分别表示男孩的数量、女孩的数量和允许的最大连续男孩数。
输出格式
输出一个整数,表示满足条件的排列方法数对 10007 10007 10007取模后的结果。
输入样例
2 1 1
输出样例
2
二叉树的构造数量
题目描述
给出一个二叉树的前序遍历序列和后序遍历序列的字符串,问通过这两个序列可以构造多少种不同的二叉树。
输入格式
输入包含两行:
- 第一行是二叉树的前序遍历序列
- 第二行是二叉树的后序遍历序列
输出格式
输出一个整数,表示可以构造的不同二叉树的数量。
输入样例
ABDCEFG
DBEGFCA
输出样例
4
Stepping Numbers
题目描述
给定 L L L 和 R R R ( 0 ≤ L ≤ R ≤ 3 × 10 8 0 \leq L \leq R \leq 3 \times 10^8 0≤L≤R≤3×108),问 [ L , R ] [L, R] [L,R] 中的自然数满足下述条件的数有多少个。
条件:数字的任意相邻两位差值都恰好为 1 1 1,且数字至少有两位。
输入格式
第一行输入一个整数 T T T,表示有 T T T 组输入。
接下来 T T T 行,每行输入两个整数 L L L 和 R R R。
输出格式
输出 T T T 行,每行一个整数表示对应测试用例的答案。
输入样例
2
1 10
1 100
输出样例
1
17
删除数字使结果最大
题目描述
给定一个数字字符串和一个整数 k k k,要求从字符串中删除 k k k个数字,使得删除后的数字字符串是所有可能情况中最大的。
例如,数字字符串为 12345678 12345678 12345678, k = 2 k=2 k=2,那么删除 1 1 1和 2 2 2,得到 345678 345678 345678是所有可能情况中最大的。
输入格式
输入包含一个数字字符串和一个整数 k k k,数字字符串长度不超过 10 5 10^5 105, k k k为非负整数且不超过数字字符串的长度。
输出格式
输出删除 k k k个数字后得到的最大数字字符串。
输入样例
12345678 2
输出样例
345678