
PAT
luer9
假如我年少有为。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
PAT 7-44 直捣黄龙(dijkstra多条件)
7-44直捣黄龙(30分)本题是一部战争大片 —— 你需要从己方大本营出发,一路攻城略地杀到敌方大本营。首先时间就是生命,所以你必须选择合适的路径,以最快的速度占领敌方大本营。当这样的路径不唯一时,要求选择可以沿途解放最多城镇的路径。若这样的路径也不唯一,则选择可以有效杀伤最多敌军的路径。输入格式:输入第一行给出2个正整数N(2≤N≤200,城镇总数)和K(城镇间道路条数),以及己方大本营和敌方大本营的代号。随后N-1行,每行给出除了己方大本营外的一个城镇的代号和驻守的敌军数量,其间...原创 2020-11-27 18:05:43 · 624 阅读 · 0 评论 -
PAT 1099 Build A Binary Search Tree (30分)
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 less than the node's key. The right subtree of a node c..原创 2020-09-21 16:01:09 · 156 阅读 · 0 评论 -
PAT 1123 Is It a Complete AVL Tree (30分)(完全二叉平衡树)
1123Is 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 is done to restore t..原创 2020-09-20 21:41:31 · 160 阅读 · 0 评论 -
PAT 1127 ZigZagging on a Tree (30分)
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 sequences. And it is a simple standard routine to print th..原创 2020-09-20 20:42:31 · 127 阅读 · 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. (2) The root is black. (3) Every leaf (NULL) is black...原创 2020-09-20 17:36:12 · 146 阅读 · 0 评论 -
PAT 1151 LCA in a Binary Tree (建树+lca)
1151LCA 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.Input Specification:Eac..原创 2020-09-20 16:04:20 · 174 阅读 · 0 评论 -
PAT 1139 First Contact (30分) (最后一个测试点超时)
1139First 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 directly in the first place. Instead, he..原创 2020-09-19 20:40:36 · 855 阅读 · 0 评论 -
PAT 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 greater than or equal to (in a max heap) or less than or equ...原创 2020-09-19 16:28:31 · 130 阅读 · 0 评论 -
PAT 1147 Heaps (30分)
1147Heaps(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 (in a max heap) or less than or equal to...原创 2020-09-19 15:24:23 · 162 阅读 · 0 评论 -
PAT 1143 Lowest Common Ancestor (30分)
1143Lowest 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 has the following propert..原创 2020-07-24 16:11:38 · 132 阅读 · 0 评论 -
PAT 1131 Subway Map (30分)
1131Subway Map(30分)In the big cities, the subway systems always look so complex to the visitors. To give you some sense, the following figure shows the map of Beijing subway. Now you are supposed to help people with your computer skills! Given the star..原创 2020-07-24 11:45:48 · 323 阅读 · 0 评论 -
PAT 1119 Pre- and Post-order Traversals (30分)
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 traversal sequences, or preorder and inorder traversal seq..原创 2020-07-23 17:23:42 · 176 阅读 · 0 评论 -
PAT 1111 Online Map (30分) (dijkstra)
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 is the fastest. It is guaranteed that a path exists for ..原创 2020-07-23 16:32:38 · 167 阅读 · 0 评论 -
PAT 1115 Counting Nodes in a BST (30分) (建树)
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 less than or equal to the node's key. The right subtree of..原创 2020-07-22 23:12:09 · 136 阅读 · 0 评论 -
PAT 1107 Social Clusters (30分)(并查集)
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 people who have some of their hobbies in common. You are...原创 2020-07-22 22:29:26 · 124 阅读 · 0 评论 -
PAT 1103 Integer Factorization (30分)
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−Pfactorization ofNfor any positive integersN,KandP....原创 2020-07-22 21:55:54 · 112 阅读 · 0 评论 -
PAT 1087 All Roads Lead to Rome (30分)
Indeed there are many different tourist routes from our city to Rome. You are supposed to find your clients the route with the least cost while gaining the most happiness.Input Specification:Each input file contains one test case. For each case, the fi原创 2020-07-22 21:03:13 · 184 阅读 · 0 评论 -
PAT 1060 Are They Equal (25分)
1060Are They Equal(25分)If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as0.123×105with simple chopping. Now given the number of significant digits on a machine and...原创 2020-07-17 16:00:37 · 141 阅读 · 0 评论 -
PAT 1033 To Fill or Not to Fill (25分)
1033To Fill or Not to Fill(25分)With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different gas station may give di..原创 2020-07-17 15:35:09 · 116 阅读 · 0 评论 -
PAT 1037 Magic Coupon (25分) (贪心)
1037Magic Coupon(25分)The magic shop in Mars is offering some magic coupons. Each coupon has an integerNprinted on it, meaning that when you use this coupon with a product, you may getNtimes the value of that product back! What is more, the shop als...原创 2020-07-16 23:51:32 · 134 阅读 · 0 评论 -
PAT 1029 Median (25分)
1029Median(25分)Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1 = { 11, 12, 13, 14 } is 12, and the median of S2 = { 9, 10, 15, 16, 17 } is 15. The median of two sequences is d..原创 2020-07-14 22:57:32 · 237 阅读 · 0 评论 -
PAT 1032 Sharing (25分)
1032Sharing(25分)To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suffix. For example,loadingandbeingare stored as sho...原创 2020-07-13 23:24:26 · 118 阅读 · 0 评论 -
PAT 1043 Is It a Binary Search Tree (25分)
1043Is 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 subtree of a node c..原创 2020-07-11 17:05:58 · 122 阅读 · 0 评论 -
PAT 1025 PAT Ranking (25分)
1025PAT Ranking(25分)Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after ..原创 2020-07-11 16:13:50 · 153 阅读 · 0 评论 -
PAT 1024 Palindromic Number (25分)(大整数相加)
1024Palindromic Number(25分)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.Non-palindromic number...原创 2020-07-10 22:59:00 · 166 阅读 · 0 评论 -
PAT 1021 Deepest Root (25分)
1021Deepest 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 is calledthe deepest root.In...原创 2020-07-10 22:22:41 · 130 阅读 · 0 评论 -
PAT 1039 Course List for Student (25分)(哈希)
1039Course List for Student(25分)Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query.Input ..原创 2020-07-10 00:01:27 · 155 阅读 · 0 评论 -
PAT 1066 Root of AVL Tree (25分) (AVL模板)
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 more than one, rebalancing is done to restore this prope..原创 2020-07-09 16:14:43 · 173 阅读 · 0 评论 -
PAT 1044 Shopping in Mars(连续子序列分割 / 二分)
1044Shopping in Mars(25分)Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and some of t..原创 2020-05-13 11:43:52 · 284 阅读 · 4 评论 -
PAT 1051 Pop Sequence (25分)
1051Pop Sequence(25分)Given a stack which can keepMnumbers at most. PushNnumbers in the order of 1, 2, 3, ...,Nand pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, ifMis ...原创 2020-05-09 18:29:47 · 266 阅读 · 2 评论 -
PAT 1056 Mice and Rice
1056Mice and Rice(25分)Mice and Riceis the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of each mouse is to eat as much rice as possible in order to becom...原创 2020-05-09 17:10:59 · 176 阅读 · 0 评论 -
PAT 1059 Prime Factors (素数筛)
1059Prime Factors(25分)Given any positive integerN, you are supposed to find all of its prime factors, and write them in the formatN=p1k1×p2k2×⋯×pmkm.Input Specification:Each input file contains one test case which giv...原创 2020-05-08 18:27:18 · 206 阅读 · 0 评论 -
PAT 1067 Sort with Swap(0, i) (贪心)
1067Sort with Swap(0, i)(25分)Given any permutation of the numbers {0, 1, 2,...,N−1}, it is easy to sort them in increasing order. But what ifSwap(0, *)is the ONLY operation that is allowed to u...原创 2020-05-07 20:44:32 · 203 阅读 · 0 评论 -
PAT 1073 Scientific Notation
1073Scientific Notation(20分)Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+-][1-9].[0-9]+E[+-]...原创 2020-05-05 20:48:23 · 120 阅读 · 0 评论 -
PAT 1074 Reversing Linked List (链表转置)
1074Reversing Linked List(25分)Given a constantKand a singly linked listL, you are supposed to reverse the links of everyKelements onL. For example, givenLbeing 1→2→3→4→5→6, ifK=3, then yo...原创 2020-05-05 17:17:59 · 138 阅读 · 0 评论 -
PAT 1079 Total Sales of Supply Chain
1079Total 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.Startin...原创 2020-05-02 14:19:52 · 200 阅读 · 0 评论 -
PAT 1086 Tree Traversals Again(中,前,后)
1086Tree 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 f...原创 2020-04-22 21:37:20 · 166 阅读 · 1 评论 -
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 ...原创 2020-04-20 17:24:02 · 144 阅读 · 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 three...原创 2020-04-18 14:44:34 · 149 阅读 · 0 评论 -
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, ...原创 2020-04-18 14:12:21 · 133 阅读 · 0 评论