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