
PAT甲级
名字被猪吃掉了
这个作者很懒,什么都没留下…
展开
-
PAT甲级 -- 1099 Build 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 less than the node's key. The right su...转载 2019-06-05 11:14:20 · 176 阅读 · 0 评论 -
PAT甲级 -- 1111 Online 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 is the fastest. It is g...转载 2019-05-30 08:55:09 · 414 阅读 · 0 评论 -
PAT甲级 -- 1053 Path of Equal Weight (30 分)
Given a non-empty tree with rootR, and with weightWiassigned to each tree nodeTi. Theweight of a path fromRtoLis defined to be the sum of the weights of all the nodes along the path fro...转载 2019-06-07 11:15:24 · 170 阅读 · 0 评论 -
PAT甲级-- 1034 Head of a Gang (30 分)
One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call betweenAandB, we say thatAandBis related. The weight of a relation is defined to be t...原创 2019-06-01 17:17:46 · 212 阅读 · 0 评论 -
PAT甲级 -- 1021 Deepest Root (25 分)
A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root ...原创 2019-06-01 16:00:46 · 312 阅读 · 0 评论 -
PAT甲级 -- 1066 Root 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 more than one, rebalancing is...转载 2019-06-06 16:43:22 · 158 阅读 · 0 评论 -
PAT甲级 -- 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 cycle ...原创 2019-05-29 11:09:24 · 215 阅读 · 0 评论 -
PAT甲级 -- 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-05-29 08:53:55 · 189 阅读 · 0 评论 -
PAT甲级 -- 1086 Tree Traversals Again (25 分)
An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stac...原创 2019-06-05 15:44:51 · 168 阅读 · 0 评论 -
PAT甲级 -- 1079 Total Sales of Supply Chain (25 分)
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 th...原创 2019-06-06 08:11:13 · 238 阅读 · 0 评论 -
PAT甲级 -- 1130
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 contai...转载 2019-05-28 19:00:12 · 231 阅读 · 0 评论 -
PAT甲级 -- 1090 Highest 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.Starting from one root supplier, everyone on th...原创 2019-06-05 14:52:14 · 164 阅读 · 0 评论 -
PAT甲级 -- 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 said...原创 2019-05-28 16:22:45 · 165 阅读 · 0 评论 -
PAT甲级 -- 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 retu...原创 2019-06-02 09:30:57 · 300 阅读 · 0 评论 -
PAT甲级 -- 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-06-02 14:24:35 · 188 阅读 · 0 评论 -
PAT甲级 -- 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 se...原创 2019-06-02 15:34:11 · 156 阅读 · 0 评论 -
PAT甲级 -- 1102 Invert 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 fuck off.Now it's your turn to...原创 2019-06-05 08:58:36 · 170 阅读 · 0 评论 -
PAT甲级 -- 1106 Lowest 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.Starting from one root supplier, everyone on th...原创 2019-06-04 17:18:58 · 239 阅读 · 0 评论 -
PAT甲级 -- 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. ...原创 2019-06-04 16:21:33 · 183 阅读 · 0 评论 -
PAT甲级 -- 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 inorder ...原创 2019-06-04 09:23:46 · 433 阅读 · 5 评论 -
PAT甲级 -- 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-06-04 08:01:37 · 173 阅读 · 0 评论 -
PAT甲级 -- 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 stand...原创 2019-06-03 17:26:29 · 327 阅读 · 0 评论 -
PAT甲级 -- 1068 Find More Coins (30 分)
Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However,...转载 2019-06-09 14:21:03 · 171 阅读 · 0 评论 -
PAT甲级 -- 1045 Favorite Color Stripe (30 分)
Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts...转载 2019-06-09 09:50:11 · 178 阅读 · 0 评论 -
PAT甲级 -- 1040 Longest Symmetric String (25 分)
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, givenIs PAT&TAP symmetric?, the longest symmetric sub-string iss PAT&TAP s, hence you ...原创 2019-06-09 08:18:35 · 230 阅读 · 0 评论 -
PAT甲级 -- 1135 Is 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. (2) The root is black. (3) Every...原创 2019-06-03 09:07:33 · 422 阅读 · 0 评论 -
PAT甲级 -- 1155 Heap 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 greater than or equal to (i...原创 2019-06-08 14:36:40 · 182 阅读 · 0 评论 -
PAT甲级 -- 1020 Tree 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 traversal sequence of the cor...原创 2019-06-02 17:07:21 · 148 阅读 · 0 评论 -
PAT甲级 -- 1043 Is It a Binary Search Tree (25 分)
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-06-08 10:09:18 · 146 阅读 · 0 评论 -
PAT甲级 -- 1094 The 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 with the largest population.Input ...原创 2019-06-05 14:25:58 · 170 阅读 · 0 评论 -
PAT -- 甲级 1006 Sign In and Sign Out (25 分)
At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you...原创 2019-05-24 09:15:11 · 193 阅读 · 0 评论 -
PAT甲级 -- 1031 Hello World for U (20 分)
Given any string ofN(≥5) characters, you are asked to form the characters into the shape ofU. For example,helloworldcan be printed as:h de ll rlowoThat is, the characters must be prin...原创 2019-05-22 10:30:39 · 230 阅读 · 0 评论 -
PAT甲级 -- 1027 Colors in Mars (20 分)
People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are forRed, the middle 2 dig...原创 2019-05-22 10:00:56 · 136 阅读 · 0 评论 -
PAT甲级 -- 1018 Public 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 return it to any other stations in the ...原创 2019-05-25 11:21:39 · 253 阅读 · 0 评论 -
PAT甲级 -- 1023 Have Fun with Numbers (20 分)
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number con...原创 2019-05-21 17:08:14 · 125 阅读 · 0 评论 -
PAT甲级 -- 1019 General Palindromic Number (20 分)
A number that will be the same when it is written forwards or backwards is known as aPalindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers...原创 2019-05-21 16:16:58 · 134 阅读 · 0 评论 -
PAT甲级 -- 1046 Shortest Distance (20 分)
The task is really simple: givenNexits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.Input Specification:Each input file conta...原创 2019-05-25 09:26:53 · 164 阅读 · 0 评论 -
PAT甲级 -- 1007 Maximum Subsequence Sum (25 分)
Given a sequence ofKintegers {N1,N2, ...,NK}. A continuous subsequence is defined to be {Ni,Ni+1, ...,Nj} where1≤i≤j≤K. The Maximum Subsequence is the continuous subsequen...原创 2019-05-25 08:18:33 · 166 阅读 · 0 评论 -
PAT甲级 -- 1014 Waiting in Line (30 分)
Suppose a bank hasNwindows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are:The space...原创 2019-05-24 19:33:11 · 159 阅读 · 0 评论 -
PAT甲级 -- 1015 Reversible Primes (20 分)
Areversible primein any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a pr...原创 2019-05-21 09:35:21 · 154 阅读 · 0 评论