PAT 甲级刷题笔记
文章平均质量分 87
备战 PAT 甲级考试,会将所有历年真题做一遍,并记录解题思路和代码。
walkerㅤ
这个作者很懒,什么都没留下…
展开
-
#1049. Counting Ones【数位DP】
原题链接Problem Description:The task is simple: given any positive integer NNN, you are supposed to count the total number of 1’s in the decimal form of the integers from 1 to NNN. For example, given NNN being 12, there are five 1’s in 1, 10, 11, and 12.Inp原创 2022-02-28 13:53:59 · 113 阅读 · 0 评论 -
#1113. Integer Set Partition【贪心】
原题链接Problem Description:Given a set of NNN (>1>1>1) positive integers, you are supposed to partition them into two disjoint sets A1A_1A1 and A2A_2A2 of n1n_1n1 and n2n_2n2 numbers, respectively. Let S1S_1S1 and S2S_2S2 denote the sums of a原创 2021-11-22 09:15:03 · 103 阅读 · 0 评论 -
#1114. Family Property【并查集】
原题链接Problem Description: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 family, and the average area an原创 2021-11-21 20:56:58 · 350 阅读 · 0 评论 -
#1089. Insert or Merge【排序】
原题链接Problem Description: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, finds the location it belongs原创 2021-11-21 19:18:33 · 211 阅读 · 0 评论 -
#1098. Insertion or Heap Sort【排序】
原题链接Problem Description: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, finds the location it belongs原创 2021-11-21 17:29:45 · 256 阅读 · 0 评论 -
#1080. Graduate Admission【模拟 + 排序】
原题链接Problem Description:It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure.Each applicant wil原创 2021-11-13 14:49:59 · 221 阅读 · 0 评论 -
#1095. Cars on Campus【模拟 + 字符串处理 + 哈希】
原题链接Problem Description:Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out times and the plate numbers of the cars crossing the gate. Now with all the information available, you are supposed to tell, at any sp原创 2021-11-13 10:13:02 · 260 阅读 · 0 评论 -
#1109. Group Photo【模拟 + 排序】
原题链接Problem Description:Formation is very important when taking a group photo. Given the rules of forming KKK rows with NNN people as the following:The number of people in each row must be N/K (round down to the nearest integer), with all the extra pe原创 2021-11-12 21:53:38 · 215 阅读 · 0 评论 -
#1062. Talent and Virtue【模拟 + 排序】
原题链接Problem Description: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原创 2021-11-12 10:12:54 · 93 阅读 · 0 评论 -
#1105. Spiral Matrix【模拟】
原题链接Problem Description:This time your job is to fill a sequence of NNN 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 mat原创 2021-11-12 09:36:15 · 102 阅读 · 0 评论 -
#1128. N Queens Puzzle【模拟 + 排序】
原题链接Problem Description:The “eight queens puzzle” is the problem of placing eight chess queens on an 8×88\times 88×8 chessboard so that no two queens threaten each other. Thus, a solution requires that no two queens share the same row, column, or diagona原创 2021-11-11 19:11:32 · 103 阅读 · 0 评论 -
#1129. Recommendation System【模拟 + 排序】
原题链接Problem Description: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 access原创 2021-11-11 17:04:00 · 231 阅读 · 0 评论 -
#1140. Look-and-say Sequence【模拟】
原题链接Problem Description:Look-and-say sequence is a sequence of integers as the following:D, D1, D111, D113, D11231, D112213111, ...where D is in [0, 9] except 1. The (n+1)st number is a kind of description of the nth number. For example, the 2nd numbe原创 2021-11-11 13:28:50 · 242 阅读 · 0 评论 -
#1044. Shopping in Mars【双指针 + 前缀和】
原题链接Problem Description: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 the原创 2021-11-10 17:59:09 · 213 阅读 · 0 评论 -
#1057. Stack【栈 + 堆 + set】
原题链接Problem Description:Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out (LIFO). The basic operations include Push (inserting an element onto the top position) and Pop (deleting the top element).原创 2021-11-09 21:01:53 · 86 阅读 · 0 评论 -
#1055. The World‘s Richest【堆 + 多路归并】
原题链接Problem Description: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 people in a certain range of ages.原创 2021-11-07 16:25:56 · 1327 阅读 · 0 评论 -
#1051. Pop Sequence【栈 + 模拟】
原题链接Problem Description:Given a stack which can keep MMM numbers at most. Push NNN numbers in the order of 1,2,3,…,N1, 2, 3, \ldots, N1,2,3,…,N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the st原创 2021-11-07 13:26:05 · 86 阅读 · 0 评论 -
#1148. Werewolf - Simple Version【枚举 + 模拟】
原题链接Problem Description: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.”;payer #2 said: “Player #3 is a human.”;playe原创 2021-11-07 10:50:55 · 117 阅读 · 0 评论 -
#1085. Perfect Sequence【双指针 + 二分】
原题链接Problem Description:Given a sequence of positive integers and another positive integer ppp. The sequence is said to be a perfect sequence if M≤m×pM\leq m\times pM≤m×p where MMM and mmm are the maximum and minimum numbers in the sequence, respectively原创 2021-11-04 16:46:39 · 80 阅读 · 0 评论 -
#1029. Median【二路归并】
原题链接Problem Description: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 sequenc原创 2021-11-04 13:38:28 · 95 阅读 · 0 评论 -
#1056. Mice and Rice【模拟】
原题链接Problem Description:Mice and Rice is 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原创 2021-11-04 09:34:19 · 108 阅读 · 0 评论 -
#1096. Consecutive Factors【数论 + 模拟】
原题链接Problem Description:Among all the factors of a positive integer NNN, there may exist several consecutive numbers. For example, 630630630 can be factored as 3×5×6×73\times 5\times 6\times 73×5×6×7, where 5, 6, and 7 are the three consecutive numbers.原创 2021-11-03 21:23:50 · 72 阅读 · 0 评论 -
#1088. Rational Arithmetic【模拟】
原题链接Problem Description:For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient.Input Specification:Each input file contains one test case, which gives in one line the原创 2021-11-03 17:54:03 · 262 阅读 · 0 评论 -
#1112. Stucked Keyboard【模拟】
原题链接Problem Description:On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the characters corresponding to those keys will appear repeatedly on screen for kkk times.Now given a resulting string on screen, you are原创 2021-11-03 16:09:17 · 90 阅读 · 0 评论 -
#1133. Splitting A Linked List【链表】
原题链接Problem Description: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][0, K][0,K] appear before all those greater than KKK. The or原创 2021-11-03 13:55:40 · 84 阅读 · 0 评论 -
#1097. Deduplication on a Linked List【链表】
原题链接Problem Description:Given a singly linked list LLL with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value KKK, only the first node of which the value or absolute value of its key e原创 2021-11-03 13:06:27 · 68 阅读 · 0 评论 -
#1074. Reversing Linked List【链表】
原题链接Problem Description:Given a constant KKK and a singly linked list LLL, you are supposed to reverse the links of every KKK elements on LLL. For example, given LLL being 1→2→3→4→5→6, if K=3K =3K=3, then you must output 3→2→1→6→5→4; if K=4K = 4K=4, you原创 2021-11-02 21:44:16 · 83 阅读 · 0 评论 -
#1032. Sharing【链表】
原题链接Problem Description: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, loading and being are stored原创 2021-11-02 20:53:48 · 95 阅读 · 0 评论 -
#1072. Gas Station【最短路 + Dijkstra】
原题链接Problem Description: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 houses are in its service range.原创 2021-11-02 20:22:27 · 90 阅读 · 0 评论 -
#1076. Forwards on Weibo【图论 + BFS】
原题链接Problem Description:Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a user makes a post on Weibo, al原创 2021-11-02 17:59:22 · 73 阅读 · 0 评论 -
#1150. Travelling Salesman Problem【图论 + 模拟】
原题链接Problem Description: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 returns to the origin city?” It is原创 2021-11-01 19:45:06 · 80 阅读 · 0 评论 -
#1142. Maximal Clique【图论 + 模拟】
原题链接Problem Description:A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. A maximal clique is a clique that cannot be extended by including one more adjacent vertex. (Quoted from htt原创 2021-11-01 17:43:17 · 125 阅读 · 0 评论 -
#1139. First Contact【图论 + 模拟】
原题链接Problem Description: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原创 2021-11-01 17:32:38 · 239 阅读 · 0 评论 -
#1134. Vertex Cover【图论 + 模拟】
原题链接Problem Description: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原创 2021-10-31 10:21:01 · 86 阅读 · 0 评论 -
#1131. Subway Map【单源最短路 + Dijkstra】
原题链接Problem Description: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 s原创 2021-10-30 17:17:23 · 109 阅读 · 0 评论 -
#1126. Eulerian Path【欧拉路径 / 欧拉回路】
原题链接Problem Description: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原创 2021-10-30 13:21:32 · 150 阅读 · 0 评论 -
#1122. Hamiltonian Cycle【图论 + 模拟】
原题链接Problem Description: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 S原创 2021-10-30 11:34:58 · 135 阅读 · 0 评论 -
#1111. Online Map【单源最短路 + Dijkstra】
原题链接Problem Description: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 f原创 2021-10-30 09:58:58 · 112 阅读 · 0 评论 -
#1087. All Roads Lead to Rome【单源最短路 + Dijkstra】
原题链接Problem Description: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 cas原创 2021-10-29 21:03:37 · 86 阅读 · 0 评论 -
#1030. Travel Plan【单源最短路 + Dijkstra】
原题链接Problem Description: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 between his/her starting city a原创 2021-10-29 12:43:41 · 88 阅读 · 0 评论