- 博客(194)
- 收藏
- 关注
原创 「1162』Postfix Expression
Given a syntax tree (binary), you are supposed to output the corresponding postfix expression, with parentheses reflecting the precedences of the operators.Input Specification:Each input f...
2022-12-02 12:33:17
289
原创 「1161」Merging Linked Lists
Given two singly linked listsand. If, you are supposed to reverse and merge the shorter one into the longer one to obtain a list like⋯. For example, given one list being 6→7 and the o...
2022-12-01 15:46:50
372
原创 『1159』Structure of a Binary Tree
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, a binary tree can be uniquely determined.Now given a sequence ...
2022-12-01 13:42:47
258
原创 「1158」Telefraud Detection
Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting victims lose their entire life savings. To stop this crime, you are supposed to write a pro...
2022-12-01 08:16:27
118
原创 「1160」Forever
“Forever number” is a positive integerAwithKdigits, satisfying the following constrains:the sum of all the digits ofAism;the sum of all the digits ofA+1isn; andthe greatest comm...
2022-12-01 03:37:53
91
原创 「1153」Decode Registration Card of PAT
A registration card number of PAT consists of 4 parts:the 1st letter represents the test level, namely,Tfor the top level,Afor advance andBfor basic;the 2nd - 4th digits are the test...
2022-11-29 17:35:53
294
原创 「1154」Vertex Coloring
Aproper vertex coloringis a labeling of the graph’s vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at mostkcolors is called a (...
2022-11-29 16:47:58
127
原创 『1157』Anniversary
Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebration, the alumni association (校友会) has gathered the ID’s of all her alumni. Now your job is ...
2022-11-29 14:38:09
85
原创 『1156」Sexy Primes
Sexy primes are pairs of primes of the form , so-named since “sex” is the Latin word for “six”. (Quoted from http://mathworld.wolfram.com/SexyPrimes.html)Now given an integer, you are suppos...
2022-11-29 12:54:03
334
原创 『1155』Heap Paths
In computer science, aheapis 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 than or eq...
2022-11-29 07:34:15
73
原创 「1147」Heaps
In computer science, aheapis 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 than or eq...
2022-11-28 17:28:07
110
原创 『1150」Travelling Salesman Problem
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 possible route that visits each city...
2022-11-28 16:20:22
128
原创 「1152」Google Recruitment
In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the picture below) for recruitment. The content is super-simple, a URL consisting of the first 1...
2022-11-28 14:52:10
100
原创 『1149』Dangerous Goods Packaging
When shipping goods with containers, we have to be careful not to pack some incompatible goods into the same container, or we might get ourselves in serious trouble. For example, oxidizing ag...
2022-11-28 13:18:28
108
原创 「1148」Werewolf - Simple Version
Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and the human beings. Suppose that in a game,player #1 said: “Player #2 is a werewolf.”;player...
2022-11-28 07:41:04
281
原创 「1151』LCA in a Binary Tree
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 are supposed to find their ...
2022-11-28 00:35:37
70
原创 『1145』Hashing - Average Search Time
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 from the table and output the av...
2022-11-27 17:00:46
143
原创 「1142」Maximal Clique
Acliqueis a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. Amaximal cliqueis a clique that cannot be extended by including one...
2022-11-27 10:37:34
113
原创 『1146」Topological Order
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 supposed to write a progra...
2022-11-27 07:17:34
95
原创 「1144」The Missing Number
Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list.Input Specification:Each input file contains one test case. For each case, the first ...
2022-11-27 05:43:10
114
原创 『1143』Lowest Common Ancestor
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 defined as a binary tree wh...
2022-11-27 04:42:38
140
原创 「1140」Look-and-say Sequence
Look-and-say sequence is a sequence of integers as the following:D, D1, D111, D113, D11231, D112213111, ...whereDis in [0, 9] except 1. The (n+1)st number is a kind of description of the ...
2022-11-26 22:19:15
57
原创 「1139」First Contact
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 not contact her d...
2022-11-26 02:46:56
99
原创 『1141』PAT Ranking of Institutions
After each PAT, the PAT Center will announce the ranking of institutions based on their students’ performances. Now you are asked to generate the ranklist.Input Specification:Each input ...
2022-11-26 01:06:08
96
原创 「1134」Vertex Cover
Avertex coverof a graph is a set of vertices such that each edge of the graph is incident to at least one vertex of the set. Now given a graph with several vertex sets, you are supposed to ...
2022-11-25 18:42:10
99
原创 「1138」Postorder Traversal
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 number of the postorder tra...
2022-11-25 15:04:59
126
原创 『1133」Splitting A Linked List
Given a singly linked list, you are supposed to rearrange its elements so that all the negative values appear before all of the non-negatives, and all the values in [0, K] appear before all t...
2022-11-25 14:34:23
54
原创 『1137』Final Grading
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 first obtain no less than 200 po...
2022-11-25 12:59:37
61
原创 『1136」A Delayed Palindrome
Consider a positive integerNwritten in standard notation withk+1digitsaiaswithfor alland. ThenNispalindromicif and only if for all. Zero is written 0 and is also palindrom...
2022-11-25 12:23:37
92
原创 『1132』Cut Integer
Cutting an integer means to cut a K digits lone integer Z into two integers of (K/2) digits long integers A and B. For example, after cutting Z = 167334, we have A = 167 and B = 334. It is in...
2022-11-25 05:44:24
75
原创 『1135』Is It A Red-Black Tree
There is a kind of balanced binary search tree namedred-black treein the data structure. It has the following 5 properties:(1) Every node is either red or black.(2) The root is black.(3...
2022-11-25 01:43:51
180
原创 『1130」Infix Expression
Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with parentheses reflecting the precedences of the operators.Input Specification:Each input fil...
2022-11-24 22:24:59
122
原创 『1129』Recommendation System
Recommendation system predicts the preference that a user would give to an item. Now you are asked to program a very simple recommendation system that rates the user’s preference by the numbe...
2022-11-24 18:15:12
146
原创 「1131」Subway Map
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 to help people...
2022-11-24 01:28:23
75
原创 「1128」N Queens Puzzle
The “eight queens puzzle” is the problem of placing eight chess queens on an8×8chessboard so that no two queens threaten each other. Thus, a solution requires that no two queens share the s...
2022-11-23 23:56:33
107
原创 「1125」Chain the Ropes
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 them into one piece, as shown by the figure. The resul...
2022-11-23 19:56:31
55
原创 「1126」Eulerian Path
In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which starts and ends on the same vertex. They ...
2022-11-23 12:46:04
73
原创 「1124」Raffle for Weibo Followers
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 would select winners from every N followers who forwarded his post, ...
2022-11-23 11:58:48
48
原创 『1127』ZigZagging on a Tree
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 sequences. And it is a sim...
2022-11-23 08:11:09
122
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人