PAT甲级
文章平均质量分 62
_Gray
这个作者很懒,什么都没留下…
展开
-
1072 Gas Station (30 分)
A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it must guarantee that all the hou...原创 2019-01-31 18:31:05 · 162 阅读 · 0 评论 -
1133 Splitting 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 in [0, K] appear before all those grea...原创 2019-01-23 02:25:47 · 83 阅读 · 0 评论 -
1059 Prime Factors (25 分)
Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1k1×p2k2×⋯×pmkm.Input Specification:Each input file co...原创 2019-01-29 00:12:33 · 92 阅读 · 0 评论 -
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-01-29 10:26:53 · 114 阅读 · 0 评论 -
1143 Lowest 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 ...原创 2019-02-04 09:40:14 · 151 阅读 · 0 评论 -
1071 Speech Patterns (25 分)
People often have a preference among synonyms of the same word. For example, some may prefer "the police", while others may prefer "the cops". Analyzing such patterns can help to narrow down a speaker...原创 2019-02-04 18:41:58 · 118 阅读 · 0 评论 -
1067 Sort 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 if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2...原创 2019-01-29 11:12:06 · 88 阅读 · 0 评论 -
1070 Mooncake (25 分)
Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of fillings and crusts can be found in traditional mooncakes according to the region's culture. Now ...原创 2019-01-29 11:48:17 · 107 阅读 · 0 评论 -
1134 Vertex Cover (25 分)
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 e...原创 2019-01-23 17:23:48 · 91 阅读 · 0 评论 -
1132 Cut 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 = 334. It is interesting...原创 2019-01-23 01:14:25 · 107 阅读 · 0 评论 -
1130 Infix Expression (25 分)
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-01-22 18:33:02 · 137 阅读 · 0 评论 -
1147 Heaps (30 分)
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 (i...原创 2019-01-27 08:39:46 · 188 阅读 · 0 评论 -
1146 Topological 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 supposed to write a program to test...原创 2019-01-27 08:42:23 · 121 阅读 · 0 评论 -
1054 The Dominant Color (20 分)
Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the d...原创 2019-01-27 09:49:26 · 210 阅读 · 0 评论 -
1055 The World's Richest (25 分)
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world's wealthiest people. Now you are supposed to simulate this job, but concentrate only on the peopl...原创 2019-01-27 20:08:01 · 198 阅读 · 0 评论 -
1114 Family 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 need to know the size of each f...原创 2019-01-16 18:56:01 · 208 阅读 · 0 评论 -
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-01-16 21:46:41 · 106 阅读 · 0 评论 -
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-01-22 16:39:18 · 203 阅读 · 0 评论 -
1116 Come on! Let's C (20 分)
"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...原创 2019-01-17 00:41:07 · 107 阅读 · 0 评论 -
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-02-21 14:45:18 · 150 阅读 · 0 评论 -
1081 Rational Sum (20 分)
Given N rational numbers in the form numerator/denominator, you are supposed to calculate their sum.Input Specification:Each input file contains one test case. Each case starts with a positive int...原创 2019-02-21 14:47:22 · 135 阅读 · 0 评论 -
1082 Read Number in Chinese (25 分)
Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output Fu first if it is negative. For example, -123456789 is read as Fu yi Yi er Qian san Bai ...原创 2019-02-21 14:48:37 · 271 阅读 · 1 评论 -
1001 A+B Format (20 分)
Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).Input Specification:Each input ...原创 2019-02-10 23:09:34 · 104 阅读 · 0 评论 -
1089 Insert or Merge (25 分)
According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data,...原创 2019-02-23 13:48:58 · 119 阅读 · 0 评论 -
1149 Dangerous 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 trouble. For example, oxidizing agent (氧化剂)...原创 2019-02-25 15:28:12 · 122 阅读 · 0 评论 -
1152 Google Recruitment (20 分)
In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the picture below) for recruitment. The content is super-simple, a URL consisting of the first 10-digit p...原创 2019-02-25 15:29:52 · 169 阅读 · 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, T for the top level, A for advance and B for basic; the 2nd - 4th digits are the test site nu...原创 2019-02-25 15:30:39 · 109 阅读 · 0 评论 -
1154 Vertex Coloring (25 分)
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...原创 2019-02-25 15:31:24 · 139 阅读 · 0 评论 -
1155 Heap Paths (30 分)
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 (i...原创 2019-02-25 15:32:49 · 167 阅读 · 0 评论 -
1118 Birds in Forest (25 分)
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 maxi...原创 2019-02-26 11:22:55 · 127 阅读 · 0 评论 -
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-01-31 02:27:51 · 381 阅读 · 0 评论 -
1053 Path of Equal Weight (30 分)
Given a non-empty tree with root R, and with weight Wi assigned to each tree node Ti. The weight of a path from R to L is defined to be the sum of the weights of all the nodes along the path fro...原创 2019-01-30 14:54:24 · 114 阅读 · 0 评论 -
1085 Perfect Sequence (25 分)
Given a sequence of positive integers and another positive integer p. The sequence is said to be a perfect sequence if M≤m×p where M and m are the maximum and minimum numbers in the sequence, respecti...原创 2019-02-21 14:50:26 · 109 阅读 · 0 评论 -
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-02-21 14:51:34 · 341 阅读 · 0 评论 -
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 ...原创 2019-02-21 14:52:55 · 191 阅读 · 0 评论 -
1098 Insertion or Heap Sort (25 分)
According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data,...原创 2019-02-21 14:58:23 · 109 阅读 · 0 评论 -
1101 Quick Sort (25 分)
There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its le...原创 2019-02-21 14:59:27 · 174 阅读 · 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 integer N (≤20) wh...原创 2019-02-21 15:01:31 · 169 阅读 · 0 评论 -
1105 Spiral Matrix (25 分)
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...原创 2019-02-21 15:03:01 · 189 阅读 · 0 评论 -
1049 Counting Ones (30 分)
The task is simple: given any positive integer N, you are supposed to count the total number of 1's in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1's i...原创 2019-01-30 05:45:04 · 84 阅读 · 0 评论