- 博客(43)
- 收藏
- 关注
原创 PAT (Advanced Level)-1102 Invert a Binary Tree
1102 Invert a Binary Tree (25 分)The following is from Max Howell @twitter:Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so ...
2018-10-17 17:03:05
144
原创 PAT (Advanced Level)-1100 Mars Numbers
PAT (Basic Level)-1044 火星数字 (20 分)1100 Mars Numbers (20 分)People on Mars count their numbers with base 13:Zero on Earth is called "tret" on Mars. The numbers 1 to 12 on Earch is called "jan, fe...
2018-10-17 14:43:30
141
原创 PAT (Advanced Level) -1101 Quick Sort
1101 Quick Sort (25 分)PAT (Basic Level)-1045 快速排序 (25 分)There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivo...
2018-10-17 14:39:22
176
原创 PAT (Advanced Level)-1106 Lowest Price in Supply Chain
1106 Lowest Price in Supply Chain (25 分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Start...
2018-10-14 16:46:51
136
原创 PAT (Advanced Level)-1107 Social Clusters(并查集)
1107 Social Clusters (30 分)When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A social cluster is a set of...
2018-10-14 16:20:53
225
原创 PAT (Advanced Level)-1114 Family Property(dfs连通域)
1114 Family Property (25 分)This time, you are supposed to help us collect the data for family-owned property. Given each person's family members, and the estate(房产)info under his/her own name, we ne...
2018-10-08 22:35:44
136
原创 PAT (Advanced Level)-1111 Online Map(dijkstra+dfs)
1111 Online Map (30 分)Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other...
2018-10-07 23:00:52
161
原创 PAT (Advanced Level) -1123 Is It a Complete AVL Tree(层序遍历平衡二叉树)
1123 Is It a Complete AVL Tree (30 分)An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they ...
2018-10-01 15:02:40
316
原创 PAT (Advanced Level)-1115 Counting Nodes in a BST
1115 Counting Nodes in a BST (30 分)A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys le...
2018-10-01 13:56:48
141
原创 PAT (Advanced Level)-1108 Finding Average(sscanf&sprintf)
PAT (Advanced Level)-1108 Finding Average (20 分)PAT (Basic Level)-1054. 求平均值(20 分)The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it com...
2018-09-29 16:14:32
172
原创 PAT (Advanced Level)-1118 Birds in Forest
1118 Birds in Forest (25 分)Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the...
2018-09-27 13:44:42
118
原创 PAT (Advanced Level)-1122 Hamiltonian Cycle
1122 Hamiltonian Cycle (25 分)The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a graph. Such a cycle is called a "Hamiltonian cycle".In this problem, you are sup...
2018-09-24 14:56:17
128
原创 PAT (Advanced Level)-1151 LCA in a Binary Tree (前中还原树LCA算法)
1151 LCA in a Binary Tree (30 分)The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants.Given any two nodes in a binary tree, you a...
2018-09-23 23:18:16
255
原创 PAT (Advanced Level)-1150 Travelling Salesman Problem
1150 Travelling Salesman Problem (25 分)The "travelling salesman problem" asks the following question: "Given a list of cities and the distances between each pair of cities, what is the shortest poss...
2018-09-23 00:24:44
137
原创 PAT (Advanced Level)-1148 Werewolf - Simple Version
1148 Werewolf - Simple Version(20 分)PAT (Basic Level)-1089 狼人杀-简单版(20 分)Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and the human beings. Suppose ...
2018-09-11 17:17:08
249
原创 PAT (Advanced Level)-1149 Dangerous Goods Packaging
1149 Dangerous Goods Packaging(25 分)PAT (Basic Level)-1090 危险品装箱(25 分)When shipping goods with containers, we have to be careful not to pack some incompatible goods into the same container, or we ...
2018-09-10 22:22:35
211
原创 PAT (Advanced Level)-1127 ZigZagging on a Tree(后序中序还原树)
1127 ZigZagging on a Tree(30 分)Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and inorder traversal se...
2018-09-10 16:39:01
240
原创 PAT (Advanced Level)-1112 Stucked Keyboard
1112 Stucked Keyboard(20 分)1112 Stucked Keyboard(20 分)On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the characters corresponding to those keys will ap...
2018-09-06 21:27:49
122
原创 PAT (Advanced Level) -1105 Spiral Matrix
1105 Spiral Matrix(25 分)PAT (Basic Level)-1050 螺旋矩阵(25 分)This time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasing order. A spiral matrix is filled in ...
2018-09-06 16:45:48
150
原创 PAT (Advanced Level)-1131 Subway Map(dfs)
1131 Subway Map(30 分)In the big cities, the subway systems always look so complex to the visitors. To give you some sense, the following figure shows the map of Beijing subway. Now you are supposed ...
2018-09-04 16:10:43
141
原创 PAT (Advanced Level)-1120 Friend Numbers(20 分)
1120 Friend Numbers(20 分)PAT (Basic Level) -1064 朋友数(20 分)Two integers are called "friend numbers" if they share the same sum of their digits, and the sum is their "friend ID". For example, 123 an...
2018-09-04 00:04:56
96
原创 PAT (Advanced Level)-1130 Infix Expression
1130 Infix Expression(25 分)Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with parentheses reflecting the precedences of the operators.Input Specifica...
2018-09-01 15:30:40
127
原创 PAT (Basic Level) -1068 万绿丛中一点红
1068 万绿丛中一点红(20 分)对于计算机而言,颜色不过是像素点对应的一个 24 位的数值。现给定一幅分辨率为 M×N 的画,要求你找出万绿丛中的一点红,即有独一无二颜色的那个像素点,并且该点的颜色与其周围 8 个相邻像素的颜色差充分大。输入格式:输入第一行给出三个正整数,分别是 M 和 N(≤ 1000),即图像的分辨率;以及 TOL,是所求像素点与相邻点的颜色差阈值,色差超过 ...
2018-08-31 22:12:43
95
原创 PAT (Advanced Level) -1128 N Queens Puzzle
1128 N Queens Puzzle(20 分)The "eight queens puzzle" is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens threaten each other. Thus, a solution requires that no two...
2018-08-31 20:47:46
87
原创 PAT (Advanced Level)-1125 Chain the Ropes
PAT (Basic Level) 1070 结绳(25 分)1125 Chain the Ropes(25 分)Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fold two segments into loops and chain th...
2018-08-31 16:21:29
200
原创 PAT (Advanced Level) -1124 Raffle for Weibo Followers
1124 Raffle for Weibo Followers(20 分)PAT (Basic Level) -1069 微博转发抽奖(20 分)John got a full mark on PAT. He was so happy that he decided to hold a raffle(抽奖) for his followers on Weibo -- that is, he...
2018-08-31 15:53:37
110
原创 PAT (Advanced Level)-1136 A Delayed Palindrome
PAT (Basic Level)-1079延迟的回文数1136 A Delayed Palindrome(20 分)Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 with 0≤ai<10 for all i and ak...
2018-08-26 16:55:31
126
原创 PAT (Basic Level) ー1081 检查密码
1081 检查密码(15 分)本题要求你帮助某网站的用户注册模块写一个密码合法性检查的小功能。该网站要求用户设置的密码必须由不少于6个字符组成,并且只能有英文字母、数字和小数点 .,还必须既有字母也有数字。输入格式:输入第一行给出一个正整数 N(≤ 100),随后 N 行,每行给出一个用户设置的密码,为不超过 80 个字符的非空字符串,以回车结束。输出格式:对每个用户的密码,在...
2018-08-26 16:16:21
129
原创 PAT (Advanced Level)-1143 Lowest Common Ancestor
1143 Lowest Common Ancestor(30 分)The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants.A binary search tree (BST) is recursively ...
2018-08-26 15:15:43
168
原创 PAT (Advanced Level)-1135 Is It A Red-Black Tree
1135 Is It A Red-Black Tree(30 分)There is a kind of balanced binary search tree named red-black tree in the data structure. It has the following 5 properties:(1) Every node is either red or black....
2018-08-24 22:57:39
195
原创 PAT (Advanced Level)-1139 First Contact
1139 First Contact(30 分)Unlike in nowadays, the way that boys and girls expressing their feelings of love was quite subtle in the early years. When a boy A had a crush on a girl B, he would usually ...
2018-08-24 16:31:24
286
原创 PAT (Advanced Level)-1133 Splitting A Linked List
1133 Splitting A Linked List(25 分)PAT (Basic Level)-1075 链表元素分类Given a singly linked list, you are supposed to rearrange its elements so that all the negative values appear before all of the non-n...
2018-08-23 16:44:23
128
原创 PAT (Advanced Level)-1138 Postorder Traversal
1138 Postorder Traversal(25 分)Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and inorder traversal sequences, you are supposed to output the first numb...
2018-08-23 14:32:52
195
原创 PAT (Advanced Level)-1137 Final Grading
1080 MOOC期终成绩1137 Final Grading(25 分)For a student taking the online course "Data Structures" on China University MOOC (http://www.icourse163.org/), to be qualified for a certificate, he/she must ...
2018-08-23 00:10:03
180
原创 PAT (Basic Level)-1083 是否存在相等的差
1083 是否存在相等的差(20 分)给定 N 张卡片,正面分别写上 1、2、……、N,然后全部翻面,洗牌,在背面分别写上 1、2、……、N。将每张牌的正反两面数字相减(大减小),得到 N 个非负差值,其中是否存在相等的差?输入格式:输入第一行给出一个正整数 N(2 ≤ N ≤ 10 000),随后一行给出 1 到 N 的一个洗牌后的排列,第 i 个数表示正面写了 i 的那张卡片背面的...
2018-08-20 22:15:12
128
原创 PAT (Advanced Level) -1140 Look-and-say Sequence
PAT (Basic Level)1084 外观数列1140 Look-and-say Sequence(20 分) 1140 Look-and-say Sequence(20 分)Look-and-say sequence is a sequence of integers as the following:D, D1, D111, D113, D11231, D112213...
2018-08-20 21:55:36
116
原创 PAT (Advanced Level)-1145 Hashing - Average Search Time
1145 Hashing - Average Search Time(25 分)The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try to find another sequence of integer keys...
2018-08-20 18:37:52
135
原创 PAT (Advanced Level)-1147 Heaps
1147 Heaps(30 分)In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater t...
2018-08-20 14:50:45
144
原创 PAT (Advanced Level) -1146 Topological Order
1146 Topological Order(25 分)This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given directed graph? Now you are suppo...
2018-08-19 22:44:03
176
原创 PAT (Advanced Level) -1141 PAT Ranking of Institutions
1141 PAT Ranking of Institutions(25 分)PAT (Basic Level)-1085 PAT单位排行(25 分)每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜。本题就请你实现这个功能。输入格式:输入第一行给出一个正整数 N(≤105),即考生人数。随后 N 行,每行按下列格式给出一个考生的信息:准考证号 得分 学校其中...
2018-08-19 18:26:24
122
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人