
PTA甲级
文章平均质量分 76
_努力努力再努力_
如果你吃不了学习的苦,那就只能吃生活的苦
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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 greater than K. The order of the elements inside each class原创 2021-12-18 10:17:51 · 113 阅读 · 0 评论 -
1064 Complete Binary Search Tree (30 分)
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 subtree of a node co原创 2021-12-18 09:46:50 · 123 阅读 · 0 评论 -
1063 Set Similarity (25 分)(超时原因)
Given two sets of integers, the similarity of the sets is defined to be Nis the total number of distinct numbers in the two sets. Your job is to calculate the similarity of any given pair of sets.Input Specification:Each input file contains one test cas原创 2021-12-18 09:22:46 · 129 阅读 · 0 评论 -
1062 Talent and Virtue (25 分)(坑点分析)
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people’s talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a “sage(圣人)”; being less excellent but with o原创 2021-12-18 09:07:56 · 136 阅读 · 0 评论 -
1065 A+B and C (64bit) (20 分)
Given three integers A, B and C in (−263,263), you are supposed to tell whether A+B>C.Input Specification:The first line of the input gives the positive number of test cases, T (≤10). Then T test cases follow, each consists of a single line contai原创 2021-12-18 08:47:24 · 92 阅读 · 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, there was a special requirement of the payment: for eac原创 2021-12-17 10:36:06 · 212 阅读 · 0 评论 -
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 subtree of a node contains only nodes with keys greater than原创 2021-12-17 09:54:37 · 109 阅读 · 0 评论 -
1048 Find Coins (25 分)
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, there was a special requirement of the payment: for eac原创 2021-12-17 09:06:49 · 173 阅读 · 0 评论 -
1038 Recover the Smallest Number (30 分)
Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like 32-321-3214-0229-87 or 0229-32-87-321-3214 with respect to different ord原创 2021-12-17 08:58:18 · 86 阅读 · 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 stack operations are: push(1); push(2); push(3); pop(); pop(原创 2021-12-16 10:25:56 · 86 阅读 · 0 评论 -
1043 Is It a Binary Search Tree (25 分)(24分代码,求助)
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 contains only nodes with keys greater than原创 2021-12-16 09:55:44 · 385 阅读 · 0 评论 -
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 prove that YOU CAN invert a binary tree!Input Specificatio原创 2021-12-16 08:51:10 · 78 阅读 · 0 评论 -
1107 Social 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. 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-12-14 10:32:40 · 99 阅读 · 0 评论 -
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 the chain buys products from one’s supplier in a price P an原创 2021-12-14 09:55:11 · 138 阅读 · 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 a clockwise spiral. The matrix has m rows and n columns原创 2021-12-14 09:34:22 · 358 阅读 · 0 评论 -
1104 Sum of Number Segments (20 分)(双重循环超时)
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence { 0.1, 0.2, 0.3, 0.4 }, we have 10 segments: (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3, 0.4) (0.2) (0.2, 0.3) (0.2, 0.3, 0.4)原创 2021-12-14 09:10:52 · 174 阅读 · 0 评论 -
1074 Reversing Linked List (25 分)(详解)
Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you must output 3→2→1→6→5→4; if K=4, you must output 4→3→2→1→5→6.Input Specification:Each原创 2021-12-13 10:46:19 · 228 阅读 · 0 评论 -
1097 Deduplication on a Linked List (25 分)
Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value K, only the first node of which the value or absolute value of its key equals K will be kept. At the m原创 2021-12-13 10:14:37 · 77 阅读 · 0 评论 -
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 guaranteed that a path exists for any request.Input Spec原创 2021-12-13 09:31:25 · 180 阅读 · 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) which is the total number of nodes in the tree – and hence t原创 2021-12-12 10:57:13 · 178 阅读 · 0 评论 -
1108 Finding Average (20 分)(18分分析)
The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be legal. A legal input is a real number in [−1000,1000] and is accurate up to no more th原创 2021-12-12 09:51:03 · 150 阅读 · 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.The right subtree of a node contains only nodes with keys原创 2021-12-12 09:24:57 · 84 阅读 · 0 评论 -
1113 Integer Set Partition (25 分)
Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint sets A ∣ is maximized.Input Specification:Each input file contains one test case. For each case, the first line gives an integer N (2≤N≤105), and then N原创 2021-12-11 09:54:18 · 81 阅读 · 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 maximum number of trees in the forest, and for any pair of b原创 2021-12-11 09:26:25 · 141 阅读 · 0 评论 -
1117 Eddington Number (25 分)
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-12-11 08:49:52 · 546 阅读 · 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 the following:0、 The Champion will receive a “Mystery原创 2021-12-09 11:17:44 · 129 阅读 · 0 评论 -
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 is a Hamiltonian cycle.Input Specification:Each input f原创 2021-12-09 10:15:03 · 312 阅读 · 0 评论 -
1121 Damn Single (25 分)
“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-12-09 09:41:14 · 111 阅读 · 0 评论 -
1120 Friend Numbers (20 分)
Two integers are called “friend numbers” if they share the same sum of their digits, and the sum is their “friend ID”. For example, 123 and 51 are friend numbers since 1+2+3 = 5+1 = 6, and 6 is their friend ID. Given some numbers, you are supposed to count原创 2021-12-09 09:23:30 · 133 阅读 · 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 standard routine to print the numbers in level-order. However原创 2021-12-09 08:48:38 · 290 阅读 · 0 评论 -
1126 Eulerian Path (25 分)(20分分析)
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-12-08 21:06:49 · 86 阅读 · 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 chain will be treated as another segment of rope and can be原创 2021-12-08 20:31:36 · 86 阅读 · 0 评论 -
1124 Raffle for Weibo Followers (20 分)
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-12-08 20:07:29 · 129 阅读 · 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 contains one test case. For each case, the first line gives a po原创 2021-12-08 19:44:50 · 148 阅读 · 0 评论 -
1129 Recommendation System (25 分)
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-12-07 09:43:38 · 161 阅读 · 0 评论 -
1128 N Queens Puzzle (20 分)(测试点二分析)
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-12-07 09:02:01 · 165 阅读 · 0 评论 -
1135 Is It A Red-Black Tree (30 分)
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-12-07 08:43:03 · 188 阅读 · 0 评论 -
PTA 甲级常见英文单词(持续更新)
吃了单词的亏,很多题都读不懂,本篇总结一些常见的单词,帮助理解题意同时避免细节上的一些问题:vertex :点,顶点graph :图edge :边no more than 1000 digits. :不超过 1000 位positive integer :正整数distinct:不同If there is a tie,:如果此时有平局(常用排序)nonnegative integer :非负整数descending order :下降序列ascending order:上升序列roun原创 2021-12-06 09:52:52 · 578 阅读 · 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 each of them is a vertex cover or not.Input Specificatio原创 2021-12-06 09:46:42 · 690 阅读 · 0 评论 -
1137 Final Grading (25 分)(最后的测试点)
For a student taking the online course “Data Structures” on China University MOOC (http://www.icourse163.org/), to be qualified for a certificate, he/she must first obtain no less than 200 points from the online programming assignments, and then receive a原创 2021-12-06 09:10:46 · 215 阅读 · 0 评论