PAT
浙大PAT刷题经验
baixiaofei567
如果十年前没种树,那最好的时间是现在
展开
-
PAT甲级 2020冬季93分总结
七月份考了乙级75,被最后一题裁判机打到哭。九月份为了复习期末考试就没有报名甲级,10月多开始复习甲级,我的复习主要有两个方面:1.看算法笔记(神书,在我眼里比算法第4版还好)。2.刷穿甲级题库,我刷了144题,有些超纲的就不做了,类似tabble tennis、树型数组之类的。我其实是个很胆小的人,看到通过很低我就不敢做了,还好这次第二题没看通过率,不然估计吓得直接做第三题了。我就有预感要考字符串,把字符串相关的问题都做了一遍,其实你只要做了坏键盘之类的那些题目,第二题是很简单的,暴力就能AC。第四题原创 2020-12-06 16:30:45 · 888 阅读 · 4 评论 -
2019年9月8日秋季PAT甲级题解-4 Dijkstra Sequence (30 分)
Dijkstra’s algorithm is one of the very famous greedy algorithms. It is used for solving the single source shortest path problem which gives the shortest paths from one particular source vertex to all the other vertices of the given graph. It was conceived原创 2020-12-04 01:17:44 · 162 阅读 · 0 评论 -
19年冬季第二题 PAT甲级 1165 Block Reversing (25分)
Given a singly linked list L. Let us consider every K nodes as a block (if there are less than K nodes at the end of the list, the rest of the nodes are still considered as a block). Your job is to reverse all the blocks in L. For example, given L as 1→2→3原创 2020-12-02 01:28:57 · 199 阅读 · 0 评论 -
PAT(甲级)2020年秋季考试 7-3 Left-View of Binary Tree (25分)
后中序列建树,easy,bfs里用一个maxLayer来判断是否到达新的一层,到新的就输出//建树然后bfs,每层第一个数就直接输出,就maxLayer来判断是否是第一次出现这个层#include<iostream>#include<unordered_map>#include<vector>#include<queue>using namespace std;int n;struct node{ int val; node* lchil.原创 2020-12-01 02:06:03 · 235 阅读 · 0 评论 -
PAT(甲级)2020年秋季考试 7-2 How Many Ways to Buy a Piece of Land (25分)
听说暴力不超时??服了,早知道9月份考了,后面那题还是树//有点像回溯算法//先遍历一整个数组,如果小于money,就++。然后再次遍历数组,i和i后面那一位(J)相加,如果小于money,就++。如果不小于,就break;#include<iostream>using namespace std;int G[10005] = {0};int main(){ int n,money,cnt=0; cin>>n>>money; for(int i = 0.原创 2020-12-01 02:01:02 · 208 阅读 · 0 评论 -
PAT(甲级)2020年秋季考试 7-1 Panda and PP Milk (20分)
画图+建模,从左往右遍历,找后面有几个连续递减的,相等的就不算,直到找到下一个比当前的大的。记录有几个连续递减的,那么当前位就是比200大几个100,因为最后的那一位就是200。然后从右往左也是这样。最后取较大值,因为我们要保证从左往右or从右往左都不会产生矛盾//判断当前位有几个连续递减的,碰到递增的就break,碰到相等的不要++,最后一个设为200//每次比前一位少100,如果和前一位相等,就赋值为一样 #include<iostream> #include<vector&.原创 2020-12-01 01:59:15 · 459 阅读 · 0 评论 -
2020年7月第3题 PAT甲级真题 Safari Park (25分)
A safari park(野生动物园)has K species of animals, and is divided into N regions. The managers hope to spread the animals to all the regions, but not the same animals in the two neighboring regions. Of course, they also realize that this is an NP complete probl原创 2020-11-30 01:15:59 · 343 阅读 · 0 评论 -
2020年7月第2题 PAT甲级真题 The Judger (25分)
A game of numbers has the following rules: at the beginning, two distinct positive integers are given by the judge. Then each player in turn must give a number to the judge. The number must be the difference of two numbers that are previously given, and mu原创 2020-11-30 01:14:10 · 391 阅读 · 0 评论 -
2020年7月第1题 PAT甲级真题 Prime Day
The above picture is from Sina Weibo, showing May 23rd, 2019 as a very cool “Prime Day”. That is, not only that the corresponding number of the date 20190523 is a prime, but all its sub-strings ended at the last digit 3 are prime numbers.Now your job is .原创 2020-11-30 01:00:48 · 144 阅读 · 0 评论 -
19年冬季第四题 PAT甲级 1167 Cartesian Tree (30分)
7-4 Cartesian Tree (30分)A Cartesian tree is a binary tree constructed from a sequence of distinct numbers. The tree is heap-ordered, and an inorder traversal returns the original sequence. For example, given the sequence { 8, 15, 3, 4, 1, 5, 12, 10, 18, 6原创 2020-11-30 00:59:27 · 220 阅读 · 0 评论 -
19年冬季第二题 PAT甲级 1166 Summit (25分)
7-3 Summit (25分)A summit (峰会) is a meeting of heads of state or government. Arranging the rest areas for the summit is not a simple job. The ideal arrangement of one area is to invite those heads so that everyone is a direct friend of everyone.Now given原创 2020-11-30 00:57:07 · 268 阅读 · 0 评论 -
2019年9月8日秋季PAT甲级题解--3 Postfix Expression (25 分)
Given a syntax tree (binary), you are supposed to output the corresponding postfix 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原创 2020-11-29 02:22:13 · 169 阅读 · 0 评论 -
2019年9月8日秋季PAT甲级题解-2-1161-Merging Linked Lists (25 分)
Given two singly linked lists L1=a1→a2→⋯→an−1→an and L2=b1→b2→⋯→bm−1→bm. If n≥2m, you are supposed to reverse and merge the shorter one into the longer one to obtain a list like a1→a2→bm→a3→a4→bm−1⋯. For exam原创 2020-11-29 02:17:02 · 270 阅读 · 0 评论 -
19年春季第四题 PAT甲级 1159 Structure of a Binary Tree(30分)
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, a binary tree can be uniquely determined.Now given a sequence of statements about the structure of the resulting tree, you are原创 2020-11-29 02:14:05 · 374 阅读 · 0 评论 -
19春第三题 PAT甲级 1158 Telefraud Detection (25分)
Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting victims lose their entire life savings. To stop this crime, you are supposed to write a program to detect those suspects from a huge amount of phone call re原创 2020-11-29 02:02:22 · 366 阅读 · 2 评论 -
19年春季第二题 PAT甲级 1157 Anniversary(25 分)
Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebration, the alumni association (校友会) has gathered the ID’s of all her alumni. Now your job is to write a program to count the number of alumniamong all the pe原创 2020-11-29 01:44:10 · 194 阅读 · 0 评论 -
19年春季第一题 PAT甲级 1156 Sexy Primes (20 分)
Sexy primes are pairs of primes of the form (p, p+6), so-named since “sex” is the Latin word for “six”. (Quoted from http://mathworld.wolfram.com/SexyPrimes.html)Now given an integer, you are supposed to tell if it is a sexy prime.Input Specification:Ea原创 2020-11-29 01:42:01 · 369 阅读 · 0 评论 -
pat处理输入输出小技巧(待更新)
getline()之前用getchar()读取空格原创 2020-11-27 01:48:56 · 299 阅读 · 0 评论 -
最大公约数和最小公倍数——辗转相除法(gcd)
最大公约数递归式:gcd(b, a % b);递归边界: if(b == 0) return a;这个递归式之所以可以这样写,是因为a和b的公约数,也是b和a%b的公约数。而且如果a<b,这个订立的结果就是将a和b交换;如果a>b,那么这个定理就可以将数据规模变小,并且减小的非常快递归边界为什么是b==0,因为0和任意一个正整数的a的最大公约数都是a(不是0),所以此时return a,就是返回最大公约数了int gcd(int a, int b){ if(b == 0) retur原创 2020-11-26 22:05:17 · 210 阅读 · 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 (in a max heap) or less than or equal to (in a min heap) t原创 2020-11-18 01:45:42 · 59 阅读 · 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 number, ranged from 101 to 999;the 5th - 10th digits give t原创 2020-11-17 01:32:03 · 99 阅读 · 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-coloring.Now you are supposed to tell if a given color原创 2020-11-17 01:03:04 · 80 阅读 · 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 prime found in consecutive digits of the natural constant原创 2020-11-17 00:56:45 · 635 阅读 · 0 评论 -
1151 LCA 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:Each input file contains one test case.原创 2020-11-17 00:54:20 · 628 阅读 · 0 评论 -
1150 Travelling Salesman Problem (25分)
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 an NP-hard problem in com原创 2020-11-16 01:45:02 · 101 阅读 · 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 (氧化剂) must not be packed with flammable liquid (易燃液体), or it原创 2020-11-16 01:44:13 · 157 阅读 · 0 评论 -
1148 Werewolf - Simple Version (20分)
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: “Player #3 is a human.”;player #3 said: “Player #4 is a原创 2020-11-16 01:42:37 · 170 阅读 · 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 (in a max heap) or less than or equal to (in a min heap) t原创 2020-11-16 01:41:47 · 68 阅读 · 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 each of the options.Input Specification:Each input f原创 2020-11-16 01:35:38 · 65 阅读 · 0 评论 -
1145 Hashing - Average Search Time (25分)
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 search time (the number of comparisons made to find whether原创 2020-11-15 02:22:56 · 81 阅读 · 0 评论 -
1144 The Missing Number (20分)
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 gives a positive integer N (≤105 ). Then N integers are原创 2020-11-15 02:19:38 · 78 阅读 · 0 评论 -
1142 Maximal Clique (25分)
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 https://en.wikipedia.org/wiki原创 2020-11-15 02:18:45 · 112 阅读 · 0 评论 -
1141 PAT Ranking of Institutions (25分)
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.Input Specification:Each input file contains one test case. For each case, the first line gives a p原创 2020-11-15 02:08:34 · 54 阅读 · 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 the following properties:The left subtree of a node cont原创 2020-11-15 02:02:29 · 116 阅读 · 1 评论 -
1140 Look-and-say Sequence (20分)
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 number means that there is one D i原创 2020-11-14 01:37:25 · 69 阅读 · 0 评论 -
1138 Postorder Traversal (25分)
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 sequence of the corresponding binary tree.Input Specifica原创 2020-11-14 01:36:07 · 110 阅读 · 1 评论 -
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原创 2020-11-14 01:35:22 · 172 阅读 · 0 评论 -
1136 A Delayed Palindrome (20分)
Consider a positive integer N written in standard notation with k+1 digits ai as ak ⋯a1 a0 with 0≤ai <10 for all i and ak >0. Then N is palindromic if and only if ai =ak−i for all i. Zero is written 0 and is原创 2020-11-14 01:32:13 · 66 阅读 · 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原创 2020-11-13 00:09:23 · 79 阅读 · 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 greater than K. The order of the elements inside each class原创 2020-11-13 00:05:42 · 128 阅读 · 0 评论