![](https://img-blog.csdnimg.cn/2019091813595558.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
PAT甲级
文章平均质量分 81
有注释的题目都值得二刷
冷眼观world
社畜
展开
-
PAT甲级完结撒花
一个半小时把后三题AC了,结果第一题一直想到最后5分钟,然后发现题目意思好像理解错了,最后输出的数貌似不是一共用过几个数组,而是声明过几个数组。就按照题目的例子,如果我只找12这个位置,按照之前的理解会输出1,实际应该输出3。因为第一个数组声明了,只不过5不够12装的,所以再声明第二个数组,6还是不够,所以声明到第三个数组,一共声明了3个数组。按照这个思路,我的代码如下:#include <iostream>#include <cstdlib>#include <v.原创 2021-09-11 17:10:32 · 144 阅读 · 0 评论 -
PAT甲级重点题目归类专项复习
Dijkstra(+DFS)1003 Emergency1018 Public Bike ManagementDFS1013 Battle Over CitiesDFS求连通块BFS1004 Counting Leaves动态规划1007 Maximum Subsequence Sum最大连续子序列和原创 2021-09-08 22:17:51 · 291 阅读 · 2 评论 -
*PAT甲级1155 Heap Paths//手动模拟反向先序序列//判断大顶堆小顶堆
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 (in a max heap) or less than or equal to (in a min heap) t原创 2021-08-15 23:46:01 · 101 阅读 · 0 评论 -
PAT甲级1154 Vertex Coloring//图结点着色问题
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 k colors is called a (proper) k-coloring.Now you are supposed to tell if a given color原创 2021-08-07 16:22:47 · 71 阅读 · 0 评论 -
PAT甲级1151 LCA in a Binary Tree//前序中序建树//LCA算法求最近公共祖先
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.Input Specification:Each input file contains one test case.原创 2021-08-15 01:32:00 · 83 阅读 · 0 评论 -
PAT甲级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 and returns to the origin city?” It is an NP-hard problem in com原创 2021-08-22 19:52:38 · 62 阅读 · 0 评论 -
PAT甲级1147 Heaps//判断大顶堆小顶堆
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 (in a max heap) or less than or equal to (in a min heap) t原创 2021-08-16 00:29:19 · 204 阅读 · 0 评论 -
PAT甲级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 program to test each of the options.Input Specification:Each input f原创 2021-08-04 00:37:54 · 147 阅读 · 0 评论 -
PAT甲级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 average search time (the number of comparisons made to find whether原创 2021-08-06 21:37:20 · 168 阅读 · 0 评论 -
*PAT甲级1143 Lowest Common Ancestor//前序中序建树//LCA算法求最近公共祖先
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 has the following properties:The left subtree of a node con原创 2021-08-15 01:21:32 · 86 阅读 · 0 评论 -
PAT甲级1142 Maximal Clique//团和极大团
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 adjacent vertex. (Quoted from wiki(graph_theory))Now it is原创 2021-08-03 22:26:13 · 134 阅读 · 0 评论 -
PAT甲级1139 First Contact//图的巧妙存储//pair的使用
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 directly in the first place. Instead, he might ask another boy C,原创 2021-08-24 19:37:04 · 304 阅读 · 0 评论 -
PAT甲级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 traversal sequence of the corresponding binary tree.Input Specifica原创 2021-07-30 17:55:21 · 75 阅读 · 0 评论 -
PAT甲级1136 A Delayed Palindrome
Consider a positive integer N written in standard notation with k+1 digits ai as ak ⋯a 1a0with 0≤ai <10 for all i and a k >0. Then N is palindromic if and only if ai =ak−i for all i. Zero is written 0 and is also palindromic by definition.Non-palin原创 2021-07-28 22:10:49 · 45 阅读 · 0 评论 -
*PAT甲级1135 Is It A Red-Black Tree//判断红黑树
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) Every leaf (NULL) is black.(4) If a node is red, then both its原创 2021-08-17 00:01:15 · 208 阅读 · 1 评论 -
PAT甲级1134 Vertex Cover
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 if each of them is a vertex cover or not.Input Specificatio原创 2021-08-02 23:00:38 · 114 阅读 · 0 评论 -
PAT甲级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 those greater than K. The order of the elements inside each class原创 2021-07-28 22:00:15 · 49 阅读 · 0 评论 -
PAT甲级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 interesting to see that Z can be devided by the product of A and B,原创 2021-07-27 13:03:15 · 90 阅读 · 0 评论 -
PAT甲级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 file contains one test case. For each case, the first line gives a po原创 2021-08-01 22:47:40 · 138 阅读 · 0 评论 -
PAT甲级1129 Recommendation System//set自定义排序妙用
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 times that an item has been accessed by this user.Input Spe原创 2021-07-26 21:35:10 · 74 阅读 · 0 评论 -
PAT甲级1128 N Queens Puzzle
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 queens share the same row, column, or diagonal. The eight queens puzzle is an examp原创 2021-07-26 17:24:42 · 70 阅读 · 0 评论 -
PAT甲级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 simple standard routine to print the numbers in level-order. However原创 2021-07-25 17:49:09 · 71 阅读 · 0 评论 -
PAT甲级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 were first discussed by Leonhard Euler while solving the famous S原创 2021-08-17 22:16:51 · 121 阅读 · 0 评论 -
PAT甲级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, and give away gifts. Now you are supposed to help him generate th原创 2021-07-23 16:18:32 · 57 阅读 · 0 评论 -
PAT甲级1123 Is It a Complete AVL Tree//建平衡二叉树//判断是否为完全二叉树
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 is done to restore this property. Figures 1-4 illustrate t原创 2021-08-12 22:28:16 · 122 阅读 · 0 评论 -
PAT甲级1122 Hamiltonian Cycle
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 cycle is a Hamiltonian cycle.Input Specification:Each input f原创 2021-07-22 17:54:05 · 59 阅读 · 0 评论 -
PAT甲级1121 Damn Single
“Damn Single (单身狗)” is the Chinese nickname for someone who is being single. You are supposed to find those who are alone in a big party, so they can be taken care of.Input Specification:Each input file contains one test case. For each case, the first li原创 2021-07-22 15:14:41 · 64 阅读 · 0 评论 -
*PAT甲级1119 Pre- and Post-order Traversals//中序后序构建二叉树
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 inorder traversal sequences. However, if only the postorder and原创 2021-08-15 00:42:58 · 88 阅读 · 0 评论 -
PAT甲级1118 Birds in Forest//并查集
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 scientists to count the maximum number of trees in the forest, and for any pair of b原创 2021-07-19 21:00:06 · 103 阅读 · 0 评论 -
PAT甲级1117 Eddington Number
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”, E – that is, the maximum integer E such that it is for E days that one rides more than E miles. Eddington’s own E原创 2021-07-18 21:38:06 · 58 阅读 · 0 评论 -
PAT甲级1116 Come on! Let‘s C
“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 as the following:0、The Champion will receive a “Mystery原创 2021-07-18 21:05:18 · 80 阅读 · 0 评论 -
PAT甲级1115 Counting Nodes in a BST//平衡二叉树
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.The right subtree of a node contains only nodes with keys原创 2021-07-17 23:20:58 · 66 阅读 · 1 评论 -
PAT甲级1114 Family Property//遍历图//并查集
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 each family, and the average area and number of sets of their原创 2021-07-18 17:28:01 · 73 阅读 · 0 评论 -
PAT甲级1112 Stucked Keyboard
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 k times.Now given a resulting string on screen, you are supposed to list all the po原创 2021-04-19 15:40:20 · 182 阅读 · 2 评论 -
PAT甲级1111 Online Map//双重Dijkstra+DFS
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 is the fastest. It is guaranteed that a path exists for any request.Input Spec原创 2021-04-22 20:01:25 · 69 阅读 · 0 评论 -
PAT甲级1110 Complete Binary Tree//判断完全二叉树
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 gives a positive integer N (≤20) which is the total number of nodes in the tree – and hence t原创 2021-04-16 20:42:17 · 113 阅读 · 0 评论 -
PAT甲级1107 Social Clusters//并查集
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 people who have some of their hobbies in common. You are supposed to find all the cl原创 2021-04-15 20:38:51 · 82 阅读 · 0 评论 -
PAT甲级1106 Lowest Price in Supply Chain//DFS
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys products from one’s supplier in a price P an原创 2021-04-12 20:59:01 · 65 阅读 · 0 评论 -
PAT甲级1105 Spiral Matrix
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 from the first element at the upper-left corner, then move in a clockwise spiral. The matrix has m rows and n columns原创 2021-04-10 21:11:09 · 65 阅读 · 0 评论 -
*PAT甲级1103 Integer Factorization//DFS
The K−P factorization of a positive integer N is to write N as the sum of the P-th power of K positive integers. You are supposed to write a program to find the K−P factorization of N for any positive integers N, K and P.Input Specification:Each input fi原创 2021-08-22 00:11:40 · 67 阅读 · 0 评论