浙大PAT甲级题目1101-1120详细代码解答
文章目录
- 浙大PAT甲级题目1101-1120详细代码解答
-
-
-
-
- 1101 Quick Sort 动态规划
- 1102 Invert a Binary Tree 树
- 1103 Integer Factorization 动态规划 难
- 1104 Sum of Number Segments 数字
- 1105 Spiral Matrix 模拟
- 1106 Lowest Price in Supply Chain 树
- 1107 Social Clusters 并查集
- 1108 Finding Average 字符串
- 1109 Group Photo 模拟
- 1110 Complete Binary Tree 树
- 1111 Online Map 图 难
- 1112 Stucked Keyboard 字符串
- 1113 Integer Set Partition 贪心
- 1114 Family Property 并查集
- 1115 Counting Nodes in a BST 树
- 1116 Come on! Let's C 模拟
- 1117 Eddington Number 模拟
- 1118 Birds in Forest 并查集
- 1119 Pre- and Post-order Traversals 树
- 1120 Friend Numbers 哈希
-
-
-
1101 Quick Sort 动态规划
There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its left and those larger than the pivot to its right. Given N distinct positive integers after a run of partition, could you tell how many elements could be the selected pivot for this partition?
For example, given N=5 and the numbers 1, 3, 2, 4, and 5. We have:
- 1 could be the pivot since there is no element to its left and all the elements to its right are larger than it;
- 3 must not be the pivot since although all the elements to its left are smaller, the number 2 to its right is less than it as well;
- 2 must not be the pivot since although all the elements to its right are la