
PAT (Advanced Level) Practice
Little Panda
入行中。。。
展开
-
PAT甲级——1089 Insert or Merge (插入、归并排序的非递归实现)
1089Insert or Merge(25分)According to Wikipedia:Insertion sortiterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one...原创 2019-07-11 17:12:42 · 297 阅读 · 0 评论 -
PAT甲级——1099 Build A Binary Search Tree (二叉搜索数)
1099Build A Binary Search Tree(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...原创 2019-05-30 17:36:38 · 368 阅读 · 0 评论 -
PAT甲级——1110 Complete Binary Tree (完全二叉树)
1110Complete Binary Tree(25分)Given a tree, you are supposed to tell if it is a complete binary tree.Input Specification:Each input file contains one test case. For each case, the first line g...原创 2019-05-18 17:30:50 · 681 阅读 · 0 评论 -
PAT甲级——1106 Lowest Price in Supply Chain (BFS)
1106Lowest 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...原创 2019-05-22 15:39:39 · 481 阅读 · 0 评论 -
PAT甲级——1102 Invert a Binary Tree (层序遍历+中序遍历)
1102Invert 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...原创 2019-05-26 16:08:36 · 251 阅读 · 0 评论 -
PAT甲级——1103 Integer Factorization (DFS)
1103Integer Factorization(30分)TheK−Pfactorization of a positive integerNis to writeNas the sum of theP-th power ofKpositive integers. You are supposed to write a program to find theK−P...原创 2019-05-26 12:34:06 · 434 阅读 · 0 评论 -
PAT甲级——1107 Social Clusters (并查集)
1107Social 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. Asocial clusteris a set of...原创 2019-05-21 16:47:44 · 313 阅读 · 0 评论 -
PAT甲级——1108 Finding Average (字符串)
1108Finding Average(20分)The basic task is simple: givenNreal numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be l...原创 2019-05-21 10:21:36 · 366 阅读 · 0 评论 -
PAT甲级——1109 Group Photo (排序)
1109Group Photo(25分)Formation is very important when taking a group photo. Given the rules of formingKrows withNpeople as the following: The number of people in each row must beN/K(round...原创 2019-05-20 21:51:23 · 420 阅读 · 0 评论 -
PAT甲级——1114 Family Property (并查集)
1114Family 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...原创 2019-05-07 21:54:18 · 269 阅读 · 0 评论 -
PAT甲级——1111 Online Map (单源最短路经的Dijkstra算法、priority_queue的使用)
1111Online 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...原创 2019-05-14 23:02:12 · 229 阅读 · 0 评论 -
PAT甲级——1101 Quick Sort (快速排序)
1101Quick Sort(25分)There is a classical process namedpartitionin the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the p...原创 2019-05-27 23:10:36 · 340 阅读 · 0 评论 -
PAT甲级——1105 Spiral Matrix (螺旋矩阵)
1105Spiral Matrix(25分)This time your job is to fill a sequence ofNpositive integers into aspiral matrixin non-increasing order. A spiral matrix is filled in from the first element at the uppe...原创 2019-05-23 17:19:20 · 264 阅读 · 0 评论 -
PAT甲级——1104 Sum of Number Segments (数学规律)
1104Sum of Number Segments(20分)Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence { 0.1, 0.2, 0.3, 0.4 }, we have 10 segme...原创 2019-05-23 19:14:52 · 269 阅读 · 0 评论 -
PAT甲级——1090 Highest Price in Supply Chain (BFS或者DFS)
1090Highest 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.Star...原创 2019-06-30 15:30:15 · 340 阅读 · 0 评论 -
PAT甲级——1091 Acute Stroke (广度优先搜索BFS)
1091Acute Stroke(30分)One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each M...原创 2019-06-29 21:23:40 · 691 阅读 · 1 评论 -
PAT甲级——1092 To Buy or Not to Buy (字符串操作、映射)
1092To Buy or Not to Buy(20分)Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However th...原创 2019-06-24 16:09:26 · 225 阅读 · 0 评论 -
PAT甲级——1093 Count PAT's (逻辑类型的题目)
1093Count PAT's(25分)The stringAPPAPTcontains twoPAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and ...原创 2019-06-23 17:13:52 · 159 阅读 · 0 评论 -
PAT甲级——1094 The Largest Generation (树的遍历)
1094The Largest Generation(25分)A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation ...原创 2019-06-22 11:47:17 · 294 阅读 · 0 评论 -
PAT甲级——1095 Cars on Campus (排序、映射、字符串操作、题意理解)
1095Cars on Campus(30分)Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out times and the plate numbers of the cars crossing the gate. Now with all the ...原创 2019-06-20 21:18:33 · 509 阅读 · 0 评论 -
PAT甲级——1096 Consecutive Factors (数学题)
1096Consecutive Factors(20分)Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3×5×6×7, where 5, 6, and 7 are the thre...原创 2019-06-09 05:27:06 · 767 阅读 · 1 评论 -
PAT甲级——1097 Deduplication on a Linked List (链表)
1097Deduplication on a Linked List(25分)Given a singly linked listLwith integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each valueK,...原创 2019-06-07 22:11:21 · 303 阅读 · 0 评论 -
PAT甲级——1100 Mars Numbers (字符串操作、进制转换)
1100Mars 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 Earth is called "jan, feb, mar, apr, may, jun, jly, aug, sep...原创 2019-05-29 21:06:47 · 302 阅读 · 0 评论 -
PAT甲级——1098 Insertion or Heap Sort (插入排序、堆排序)
1098Insertion or Heap Sort(25分)According to Wikipedia:Insertion sortiterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort remo...原创 2019-06-05 21:09:04 · 450 阅读 · 0 评论 -
PAT甲级——1112 Stucked Keyboard (字符串操作+stl)
1112Stucked 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 fo...原创 2019-05-09 16:47:30 · 419 阅读 · 0 评论 -
PAT甲级——1119 Pre- and Post-order Traversals(先序+后序序列,建立二叉树)
1119Pre- 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 t...原创 2019-05-01 13:36:39 · 475 阅读 · 0 评论 -
PAT甲级——1128 N Queens Puzzle (20 分)
1128N 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 n...原创 2019-04-07 20:52:27 · 340 阅读 · 0 评论 -
PAT甲级——1135 Is It A Red-Black Tree (30 分)
1135Is It A Red-Black Tree(30分)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...原创 2019-03-28 10:47:11 · 748 阅读 · 0 评论 -
PAT甲级——1132 Cut Integer (20 分)
1132Cut Integer(20分)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...原创 2019-04-01 16:57:45 · 146 阅读 · 0 评论 -
PAT甲级——1125 Chain the Ropes (25 分)
1125Chain 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 t...原创 2019-04-10 21:30:03 · 295 阅读 · 0 评论 -
PAT甲级——1133 Splitting A Linked List (25 分)
1133Splitting 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 i...原创 2019-04-01 12:06:56 · 214 阅读 · 0 评论 -
PAT甲级——1129 Recommendation System(重载set的operator函数)
1129 Recommendation System(重载set的operator<()函数)发布完上一篇文章之后再网上发现了更简单的做法,重载set里的operator<()函数以实现自定义顺序的集合,每次输出集合里面的前K个数值就行;题目就不重复搬了,直接上代码:#include <iostream>#include<unordered_map>...原创 2019-04-05 22:32:36 · 138 阅读 · 0 评论 -
PAT甲级——1129 Recommendation System (25 分)
1129Recommendation 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 ...原创 2019-04-05 12:54:24 · 622 阅读 · 0 评论 -
PAT甲级——1130 Infix Expression (25 分)
1130Infix Expression(25分)(找规律、二叉树的遍历)Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with parentheses reflecting the precedences of the operators.In...原创 2019-04-04 21:44:05 · 311 阅读 · 1 评论 -
PAT甲级——1134 Vertex Cover (25 分)
1134Vertex 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 se...原创 2019-03-29 17:12:18 · 161 阅读 · 0 评论 -
PAT甲级--1136 A Delayed Palindrome (20 分)
1136A Delayed Palindrome(20分)Consider a positive integerNwritten in standard notation withk+1digitsaiasak⋯a1a0with0≤ai<10for alliandak>0. ThenNispalindro...原创 2019-03-21 21:15:26 · 205 阅读 · 0 评论 -
PAT甲级——1127 ZigZagging on a Tree (30 分)
1127ZigZagging on a Tree(蛇形打印二叉树)1127ZigZagging 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...原创 2019-04-08 15:47:53 · 241 阅读 · 0 评论 -
PAT甲级——1126 Eulerian Path (25 分)
1126Eulerian 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 ...原创 2019-04-09 17:15:18 · 425 阅读 · 0 评论 -
PAT甲级——1124 Raffle for Weibo Followers (set或者unordered_set的应用)
1124Raffle 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 N fo...原创 2019-04-12 21:14:06 · 145 阅读 · 0 评论 -
PAT甲级——1115 Counting Nodes in a BST (二叉搜索树)
1115Counting 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...原创 2019-05-06 12:15:14 · 271 阅读 · 0 评论