普通人跨考浙大计算机的经验贴（2019） 目录写在前面个人概况初试数学专业课数据结构组原和OS网络英语政治复试机试面试总结先说说我的基本情况：我经历自认算是比较曲折。我2016年就本科毕业了，专业土木工程，与计算机几乎毫无交集（这点毫无夸张，我本科期间计算机公共课学的是VB），毕业后才下定决心转专业，但是因为一些原因从毕业后一直没能正式着手，直到2017年8月才开始第一次备考...

PAT-A1155 Heap Paths 题目内容及题解 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...

PAT-A1154 Vertex Coloring 题目内容及题解 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...

PAT-A1153/B1095 Decode Registration Card of PAT/解码PAT准考证 题目内容及题解 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...

PAT-A1152/B1094 Google Recruitment/谷歌的招聘 题目内容及题解 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...

PAT-A1151 LCA in a Binary Tree 题目内容及题解 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...

PAT-A1150 Travelling Salesman Problem 题目内容及题解 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...

PAT-A1149/B1090 Dangerous Goods Packaging/危险品装箱 题目内容及题解 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 （氧化剂）...

PAT-A1148/B1089 Werewolf - Simple Version/狼人杀-简单版 题目内容及题解 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...

PAT-A1147 Heaps 题目内容及题解 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...

PAT-A1146 Topological Order 题目内容及题解 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...

PAT-A1145 Hashing - Average Search Time 题目内容及题解 The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try to find another sequence of integer keys from the table and output the average sea...

PAT-A1144 The Missing Number 题目内容及题解 Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list.Input Specification:Each input file contains one test case. For each case, the first line giv...

PAT-A1143 Lowest Common Ancestor 题目内容及题解 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 ...

PAT-A1142 Maximal Clique 题目内容及题解 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 adj...

PAT-A1141/B1085 PAT Ranking of Institutions/PAT单位排行 题目内容及题解 After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the ranklist.每次 PAT 考试结束后，考试中心都会发布一个考生单位排行榜。本题就请你实现这个功能。...

PAT-A1140/B1084 Look-and-say Sequence/外观数列 题目内容及题解 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 desc...

PAT-A1139 First Contact 题目内容及题解 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 i...

PAT-A1138 Postorder Traversal 题目内容及题解 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...

PAT-A1137/B1080 Final Grading/MOOC期终成绩 题目内容及题解 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...

PAT-A1136/B1079 A Delayed Palindrome/延迟的回文数 题目内容及题解 Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 with 0≤ai<10 for all i and ak>0. Then N is palindromic if and only if ai=ak−i for...

PAT-A1135 Is It A Red-Black Tree 题目内容及题解 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...

PAT-A1134 Vertex Cover 题目内容及题解 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...

PAT-A1133/B1075 Splitting A Linked List/链表元素分类 题目内容及题解 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...

PAT-A1132 Cut Integer 题目内容及题解 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...

PAT-A1131 Subway Map 题目内容及题解 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 you...

PAT-A1130 Infix Expression 题目内容及题解 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...

PAT-A1129 Recommendation System 题目内容及题解 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 time...

PAT-A1128 N Queens Puzzle 题目内容及题解 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, ...

PAT-A1127 ZigZagging on a Tree 题目内容及题解 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...

PAT-A1126 Eulerian Path 题目内容及题解 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...

PAT-A1125/B1070 Chain the Ropes/结绳 题目内容及题解 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 chai...

PAT-A1124/B1069 Raffle for Weibo Followers/微博转发抽奖 题目内容及题解 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...

PAT-A1123 Is It a Complete AVL Tree 题目内容及题解 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...

PAT-A1122 Hamiltonian Cycle 题目内容及题解 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 ...

PAT-A1121/B1065 Damn Single/单身狗 题目内容及题解 "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.“单身狗”是中文对于单身人士的一种爱称。本题请你从上万人的大型...

PAT-A1120/B1064 Friend Numbers/朋友数 题目内容及题解 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 ...

PAT-A1119 Pre- and Post-order Traversals 题目内容及题解 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 ...

PAT-A1118 Birds in Forest 题目内容及题解 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...

PAT-A1117/B1060 Eddington Number/爱丁顿数 题目内容及题解 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 ...

PAT-A1116/B1059 Come on! Let's C/C语言竞赛 题目内容及题解 "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...

PAT-A1115 Counting Nodes in a BST 题目内容及题解 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. ...

PAT-A1114 Family Property 题目内容及题解 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...

PAT-A1113 Integer Set Partition 题目内容及题解 Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint sets A1 and A2 of n1 and n2 numbers, respectively. Let S1 and S2 denote the sums of a...

PAT-A1112 Stucked Keyboard 题目内容及题解 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 k times.Now given a result...

PAT-A1111 Online Map 题目内容及题解 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...

PAT-A1110 Complete Binary Tree 题目内容及题解 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...

PAT-A1109/B1055 Group Photo/集体照 题目内容及题解 Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following:The number of people in each row must be N/K (round down to the nearest intege...

PAT-A1108/B1054 Finding Average/求平均值 题目内容及题解 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...

PAT-A1107 Social Clusters 题目内容及题解 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 thei...

PAT-A1106 Lowest Price in Supply Chain 题目内容及题解 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...

PAT-A1105/B1050 Spiral Matrix/螺旋矩阵 题目内容及题解 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...

PAT-A1104/B1049 Sum of Number Segments/数列的片段和 题目内容及题解 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...

PAT-A1103 Integer Factorization 题目内容及题解 The K−P factorization of a positive integer N is to write N as the sum of the P-th power of K positive integers. You are supposed to write a program to find the K−P factorization of N for any positive...

PAT-A1102 Invert a Binary Tree 题目内容及题解 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...

PAT-A1101/B1045 Quick Sort/快速排序 题目内容及题解 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...

PAT-A1100/B1044 Mars Numbers/火星数字 题目内容及题解 People on Mars count their numbers with base 13:Zero on Earth is called "tret" on Mars. The numbers 1 to 12 on Earch is called "jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" on Mars, ...

PAT-A1099 Build A Binary Search Tree 题目内容及题解 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...

PAT-A1098 Insertion or Heap Sort 题目内容及题解 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,...

PAT-A1097 Deduplication on a Linked List 题目内容及题解 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 a...

PAT-A1096 Consecutive Factors 题目内容及题解 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 consecutive numbers. Now given ...

PAT-A1095 Cars on Campus 题目内容及题解 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 a...

PAT-A1094 The Largest Generation 题目内容及题解 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 ...

PAT-A1093/B1040 Count PAT's/有几个PAT 题目内容及题解 The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters.Now ...

PAT-A1092/B1039 To Buy or Not to Buy/到底买不买 题目内容及题解 Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sel...

PAT-A1091 Acute Stroke 题目内容及题解 One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI slice, your job is to c...

PAT-A1090 Highest Price in Supply Chain 题目内容及题解 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...

PAT-A1089/B1035 Insert or Merge/插入与归并 题目内容及题解 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,...

PAT-A1088/B1034 Rational Arithmetic/有理数四则运算 题目内容及题解 For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient.本题要求编写程序，计算 2 个有理数的和、差、积、商。Input Specification:Each i...

PAT-A1087 All Roads Lead to Rome 题目内容及题解 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 ...

PAT-A1086 Tree Traversals Again 题目内容及题解 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...

PAT-A1085/B1030 Perfect Sequence/完美数列 题目内容及题解 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...

PAT-A1084/B1029 Broken Keyboard/旧键盘 题目内容及题解 On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.Now given a string that you are supposed to...

PAT-A1083 List Grades 题目内容及题解 Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of which the grades ...

PAT-A1082 Read Number in Chinese 题目内容及题解 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 ...

PAT-A1081 Rational Sum 题目内容及题解 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...

PAT-A1080 Graduate Admission 题目内容及题解 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...

PAT-A1079 Total Sales of Supply Chain 题目内容及题解 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...

PAT-A1078 Hashing 题目内容及题解 The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to be H(key)=key%TSiz...

PAT-A1077 Kuchiguse 题目内容及题解 The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker's personality. Such a preference is called ...

PAT-A1076 Forwards on Weibo 题目内容及题解 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 ...

PAT-A1075 PAT Judge 题目内容及题解 The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT.Input Specification:Each input file co...

PAT-A1074/B1025 Reversing Linked List/反转链表 题目内容及题解 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,...

PAT-A1073/B1024 Scientific Notation/科学计数法 题目内容及题解 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[+-][0-9]+ which means that the inte...

PAT-A1072 Gas Station 题目内容及题解 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...

PAT-A1071 Speech Patterns 题目内容及题解 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...

PAT-A1070/B1020 Mooncake/月饼 题目内容及题解 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 ...

PAT-A1069/B1019 The Black Hole of Numbers/数字黑洞 题目内容及题解 For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by takin...

PAT-A1068 Find More Coins 题目内容及题解 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,...

PAT-A1067 Sort with Swap(0, i) 题目内容及题解 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...

PAT-A1066 Root of AVL Tree 题目内容及题解 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...

PAT-A1065 A+B and C (64bit) 题目内容及题解 Given three integers A, B and C in [−2^63,2^63], 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). T...

PAT-A1064 Complete Binary Search Tree 题目内容及题解 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...

PAT-A1063 Set Similarity 题目内容及题解 Given two sets of integers, the similarity of the sets is defined to be Nc/Nt×100%, where Nc is the number of distinct common numbers shared by the two sets, and Nt is the total number of ...

PAT-A1062/B1015 Talent and Virtue/德才论 题目内容及题解 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 virt...

PAT-A1061/B1014 Dating/福尔摩斯的约会 题目内容及题解 Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm. It took him only a minute to figure out that those strange strings...

PAT-A1060 Are They Equal 题目内容及题解 If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123×10^5 with simple chopping. Now given the number of signi...

PAT-A1059 Prime Factors 题目内容及题解 Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1^k1×p2^k2×⋯×pm^km.Input Specification:Each input file...

PAT-A1058 A+B in Hogwarts 题目内容及题解 If you are a fan of Harry Potter, you would know the world of magic has its own currency system -- as Hagrid explained it to Harry, "Seventeen silver Sickles to a Galleon and twenty-nine Knuts to a Si...

PAT-A1057 Stack 题目内容及题解 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 Po...