
PAT(甲级)
记录刷题历程,每道题都有详解!
李小白~
一个算法小白的成长历程!
展开
-
1155 Heap Paths (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 than or equal to...原创 2020-05-05 18:02:12 · 245 阅读 · 1 评论 -
1154 Vertex Coloring (25分)
题目A proper vertex coloring is 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 most kkk colors is called a (prop...原创 2020-05-05 17:34:20 · 209 阅读 · 0 评论 -
1153 Decode Registration Card of PAT (25分)
题目A registration card number of PAT consists of 4 parts:the 1st letter represents the test level, namely, T for the top level, A for advance and B for basic;the 2nd - 4th digits are the test site ...原创 2020-05-05 17:06:18 · 153 阅读 · 0 评论 -
1152 Google Recruitment (20分)
题目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 10-digi...原创 2020-05-05 11:56:26 · 325 阅读 · 0 评论 -
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 are supposed to find their LCA.I...原创 2020-05-03 22:51:30 · 307 阅读 · 0 评论 -
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 possible route that visits each city and r...原创 2020-05-03 17:35:33 · 259 阅读 · 0 评论 -
1149 Dangerous Goods Packaging (25分)
题目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 agent (氧...原创 2020-05-03 11:25:21 · 384 阅读 · 0 评论 -
1148 Werewolf - Simple Version (20分)
题目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 #2 sa...原创 2020-05-03 10:22:20 · 291 阅读 · 0 评论 -
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 than or equal to...原创 2020-04-30 14:12:13 · 195 阅读 · 0 评论 -
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 supposed to write a program to t...原创 2020-04-30 12:57:58 · 270 阅读 · 0 评论 -
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 from the table and output the average ...原创 2020-04-30 11:08:17 · 185 阅读 · 0 评论 -
1144 The Missing Number (20分)
题目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 line gi...原创 2020-04-28 19:41:12 · 193 阅读 · 0 评论 -
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 defined as a binary tree which ha...原创 2020-04-28 16:17:53 · 326 阅读 · 0 评论 -
1142 Maximal Clique (25分)
题目A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. A maximal clique is a clique that cannot be extended by including one more ...原创 2020-04-28 13:10:26 · 196 阅读 · 0 评论 -
1141 PAT Ranking of Institutions (25分)
题目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 file cont...原创 2020-04-20 21:09:35 · 212 阅读 · 0 评论 -
1140 Look-and-say Sequence (20分)
题目Look-and-say sequence is a sequence of integers as the following:D, D1, D111, D113, D11231, D112213111, …where D is in [0, 9] except 1. The (n+1)st number is a kind of description of the nth nu...原创 2020-04-20 16:51:37 · 181 阅读 · 0 评论 -
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 not contact her directl...原创 2020-04-18 22:05:55 · 1815 阅读 · 0 评论 -
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 number of the postorder traversal...原创 2020-04-16 21:55:18 · 376 阅读 · 0 评论 -
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 first obtain no less than 200 points f...原创 2020-04-06 17:48:45 · 310 阅读 · 0 评论 -
1136 A Delayed Palindrome (20分)
题目Consider a positive integer NNN written in standard notation with k+1k+1k+1 digits aia_iai as ak⋯a1a0a_k⋯a_1 a_0ak⋯a1a0 with 0≤ai<100\le a_i\lt100≤ai<10 for all iii and ak>0a_k\gt0ak...原创 2020-04-06 16:36:13 · 188 阅读 · 0 评论 -
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.(2) The root is black.(3) Ever...原创 2020-04-06 15:04:53 · 262 阅读 · 0 评论 -
1134 Vertex Cover (25分)
题目A vertex cover of 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 tell i...原创 2020-04-06 11:25:21 · 218 阅读 · 0 评论 -
1133 Splitting A Linked List (25分)
题目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][0, K][0,K] appear before a...原创 2020-04-05 19:31:00 · 147 阅读 · 0 评论 -
1132 Cut Integer (20分)
题目Cutting an integer means to cut a KKK digits lone integer ZZZ into two integers of (K/2)(K/2)(K/2) digits long integers AAA and BBB. For example, after cutting Z=167334Z = 167334Z=167334, we have A...原创 2020-04-05 15:12:52 · 292 阅读 · 0 评论 -
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 Specification:Each input file conta...原创 2020-03-30 11:46:27 · 355 阅读 · 0 评论 -
1129 Recommendation System - (25分)
题目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 number of t...原创 2020-03-30 10:51:07 · 291 阅读 · 0 评论 -
1128 N Queens Puzzle (20分)
题目The “eight queens puzzle” is the problem of placing eight chess queens on an 8×88\times88×8 chessboard so that no two queens threaten each other. Thus, a solution requires that no two queens share ...原创 2020-03-28 21:46:18 · 250 阅读 · 0 评论 -
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 sequences. And it is a simple st...原创 2020-03-28 16:26:32 · 1379 阅读 · 0 评论 -
1126 Eulerian Path (25分)
题目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 were f...原创 2020-03-28 11:38:54 · 199 阅读 · 0 评论 -
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 them into one piece, as shown by the figure. The resulting c...原创 2020-03-28 00:05:51 · 152 阅读 · 0 评论 -
1124 Raffle for Weibo Followers (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 would select winners from every NNN followers who forwarded his post, and ...原创 2020-03-27 17:17:37 · 172 阅读 · 0 评论 -
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 differ by more than one, rebalancing...原创 2020-03-27 16:04:39 · 332 阅读 · 0 评论 -
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 supposed to tell if a given cycl...原创 2020-03-27 14:54:33 · 271 阅读 · 0 评论 -
1119 Pre- and Post-order Traversals (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 sequences, or preorder and inord...原创 2020-03-27 11:27:54 · 240 阅读 · 0 评论 -
1117 Eddington Number (25分)
题目British astronomer Eddington liked to ride a bike. It is said that in order to show off his skill, he has even defined an “Eddington number”, EEE – that is, the maximum integer EEE such that it is ...原创 2020-03-25 16:19:13 · 173 阅读 · 0 评论 -
1116 Come on! Let's C (20分)
题目“Let’s C” is a popular and fun programming contest hosted by the College of Computer Science and Technology, Zhejiang University. Since the idea of the contest is for fun, the award rules are funny...原创 2020-03-25 15:28:50 · 156 阅读 · 0 评论 -
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 less than or equal to the node’s key...原创 2020-03-25 12:38:45 · 117 阅读 · 0 评论 -
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 need to know the size of eac...原创 2020-03-25 11:31:06 · 176 阅读 · 0 评论 -
1113 Integer Set Partition (25分)
题目Given a set of N(>1)N(\gt1)N(>1) positive integers, you are supposed to partition them into two disjoint sets A1A_1A1 and A2A_2A2 of n1n_1n1 and n2n_2n2 numbers, respectively. Let S1S_1S1...原创 2020-03-25 09:44:20 · 151 阅读 · 0 评论 -
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 appear repeatedly on screen for kkk times.Now given a re...原创 2020-03-25 00:07:09 · 119 阅读 · 0 评论