PAT甲级
文章平均质量分 88
TheWise_lzy
已毕业,社畜一枚
展开
-
2019 PAT甲级秋季考试7-4 Dijkstra Sequence (30 分)
Dijkstra's algorithm is one of the very famous greedy algorithms. It is used for solving the single source shortest path problem which gives the shortest paths from one particular source vertex to all...原创 2019-09-09 13:59:41 · 551 阅读 · 1 评论 -
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-08-31 22:33:23 · 866 阅读 · 0 评论 -
1142 Maximal Clique (25 分) 判断最大团
1142Maximal Clique(25分)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 extend...原创 2019-08-22 21:05:28 · 270 阅读 · 0 评论 -
1089 Insert or Merge (25 分) 插入排序or归并排序
According to Wikipedia:Insertion sortiterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data,...原创 2019-08-22 17:55:47 · 234 阅读 · 0 评论 -
1123 Is It a Complete AVL Tree (30 分) 构造AVL输出层次遍历并判断是否为完全二叉树
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...原创 2019-08-17 21:38:43 · 289 阅读 · 0 评论 -
1066 Root of AVL Tree (25 分) 构造平衡二叉树并输出根节点
1066Root of AVL Tree(25分)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...原创 2019-08-16 21:57:26 · 246 阅读 · 0 评论 -
1146 Topological Order (25 分) 拓扑序列是否合法
1146Topological 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 supp...原创 2019-08-21 21:40:03 · 143 阅读 · 0 评论 -
1145 Hashing - Average Search Time (25 分) 建立Hash表并输出平均查询次数
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 sea...原创 2019-08-21 21:11:24 · 137 阅读 · 0 评论 -
1103 Integer Factorization (30 分) dfs 剪枝
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−Pfactorization ofNfor any positive...原创 2019-08-12 21:51:15 · 109 阅读 · 0 评论 -
1091 Acute Stroke (30 分) 三维广搜bfs
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 MRI slice, your job is to c...原创 2019-08-12 20:50:06 · 168 阅读 · 0 评论 -
[PAT] 模板整理
1.并查集int fa[MAX];int find(int x){ int r=x,i=x,j; while(fa[r]!=r) r=fa[r]; while(fa[i]!=i) j=fa[i],fa[i]=r,i=j; return r;}void combine(int x,int y){ int xx=find(x); int yy=find(y); if(...原创 2019-08-12 19:47:17 · 375 阅读 · 0 评论 -
11-散列4 Hashing - Hard Version (30 分) 散列表反向思维——用拓扑排序做
Given a hash table of sizeN, we can define a hash functionH(x)=x%N. Suppose that the linear probing is used to solve collisions, we can easily obtain the status of the hash table with a given sequen...原创 2019-08-25 21:10:35 · 282 阅读 · 0 评论 -
1108 Finding Average (20 分) 字符串处理 sscanf和sprintf 格式化
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 legal. Alegalinput is a real...原创 2019-09-01 14:18:45 · 286 阅读 · 0 评论 -
1109 Group 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 down to the nearest inte...原创 2019-09-01 15:04:20 · 170 阅读 · 0 评论 -
1110 Complete 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 gives a positive integerN(≤20) wh...原创 2019-09-01 15:36:58 · 174 阅读 · 0 评论 -
2019 PAT甲级秋季考试7-3 Postfix (25 分)
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 file cont...原创 2019-09-09 13:58:08 · 271 阅读 · 3 评论 -
2019 PAT甲级秋季考试7-2 Merging Linked Lists (25 分)
Given two singly linked listsL1=a1→a2→⋯→an−1→anandL2=b1→b2→⋯→bm−1→bm. Ifn≥2m, you are supposed to reverse and merge the shorter one into the longer one to obtain a li...原创 2019-09-09 13:55:35 · 575 阅读 · 0 评论 -
2019 PAT甲级秋季考试7-1 Forever (20 分)
"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; and the greatest common divi...原创 2019-09-09 13:53:52 · 805 阅读 · 1 评论 -
2019 PAT甲级秋季考试总结
因为要考研浙大软院,所以考个PAT甲级抵机试是很好的!而且之前天梯赛金奖发了150的代金券,让原价256的考试看起来也没那么贵了~于是很早就报名啦!(但是很后悔3月份那场没报,不然就可以更早轻松一点了我暑假是在家复习考研的,从8.20开始每晚只AC,开始10天在恶补树的相关知识(没错我的树很差555),从树的遍历到BST,AVL,堆,到最后我每天自己写一遍AVL,已经可以3min打完平衡函数了...原创 2019-09-09 08:00:37 · 4447 阅读 · 24 评论 -
1127 ZigZagging on a Tree (30 分) 后序和中序遍历建树后输出Z字形层次遍历
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 of postorder and inorder traversal s...原创 2019-09-05 15:59:48 · 304 阅读 · 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 firs...原创 2019-09-05 15:35:18 · 177 阅读 · 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 chai...原创 2019-09-05 15:14:09 · 129 阅读 · 0 评论 -
2019.3 PAT甲级-4 Structure of a Binary Tree (30 分) 二叉树的判断(后序中序建树)
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 of state...原创 2019-09-04 16:51:08 · 303 阅读 · 0 评论 -
2019.3 PAT甲级-3 Telefraud Detection (25 分) 并查集
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 program to d...原创 2019-09-04 16:49:49 · 274 阅读 · 0 评论 -
1102 Invert a Binary Tree (25 分) 翻转二叉树并输出层次遍历和中序遍历
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-09-02 20:22:16 · 159 阅读 · 0 评论 -
1043 Is It a Binary Search Tree (25 分) 建立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 the node's key. The right su...原创 2019-08-15 20:59:18 · 520 阅读 · 0 评论 -
1064 Complete 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 less than the node's key. The right su...原创 2019-08-15 20:00:12 · 256 阅读 · 0 评论 -
1020 Tree Traversals (25 分) 给出后序和中序遍历,输出层序遍历
1020Tree Traversals(25分)Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order ...原创 2019-08-18 21:22:19 · 194 阅读 · 0 评论 -
1004 Counting Leaves (30 分) 输出树每层的叶子节点数
A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file contains one test case. Each case starts...原创 2019-08-18 20:40:12 · 142 阅读 · 0 评论 -
1018 Public Bike Management (30 分) dijstra+dfs 输出最短路路径
1018Public Bike Management(30分)There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and ret...原创 2019-08-08 22:37:45 · 168 阅读 · 0 评论 -
1003 Emergency (25 分) dijstra输出最短路径条数 / floyd+dfs
1003Emergency(25分)As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue te...原创 2019-08-08 21:12:45 · 153 阅读 · 0 评论 -
1149 Dangerous Goods Packaging (25 分)
1149Dangerous 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 trou...原创 2019-03-28 20:16:25 · 173 阅读 · 0 评论 -
1150 Travelling Salesman Problem (25 分) 模拟
1150Travelling 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...原创 2019-03-28 19:58:32 · 170 阅读 · 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.In...原创 2019-03-29 14:19:26 · 215 阅读 · 0 评论 -
1148 Werewolf - Simple Version (20 分) 暴力模拟
1148Werewolf - 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: "Pla...原创 2019-03-29 14:13:35 · 470 阅读 · 0 评论 -
1155 Heap Paths (30 分) 判断大小顶堆
1155Heap Paths(30分)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 gre...原创 2019-03-20 20:56:07 · 319 阅读 · 0 评论 -
1154 Vertex Coloring (25 分)
1154Vertex Coloring(25分)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 mostk...原创 2019-03-20 20:52:07 · 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,Tfor the top level,Afor advance andBfor basic; the 2nd - 4th digits are the test site nu...原创 2019-03-20 20:49:18 · 207 阅读 · 0 评论 -
1115 Counting Nodes in a BST (30 分) 二叉搜索树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. ...原创 2019-08-13 21:16:35 · 150 阅读 · 0 评论 -
1030 Travel Plan (30 分) dijstra最短路+dfs回溯路径
A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path b...原创 2019-08-09 21:20:12 · 236 阅读 · 0 评论