![](https://img-blog.csdnimg.cn/20190927151132530.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
PAT
fighting!!!
还记得樱花正开~
这个作者很懒,什么都没留下…
展开
-
PAT2020秋第一题熊猫喝牛奶
题意给出n个熊猫的体重,它们排成一行,给它们分配牛奶喝,要求最少的牛奶总量。最少的牛奶量是200,每次牛奶增加量是100.邻居熊猫如果体重相同就分配同等量的牛奶,如果体重不同,体重大的熊猫需要喝更多的牛奶思路两次扫描,从左向右和从右向左。如果体重在增加,牛奶也增加100,如果体重增加结束,牛奶就从200开始。取两次扫描结果的最大值。代码#include<stdio.h>#include<algorithm>using namespace std;const原创 2020-09-08 15:55:46 · 447 阅读 · 6 评论 -
PAT2019春7-4 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-09-06 09:42:00 · 164 阅读 · 0 评论 -
PAT2019春7-3 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-09-05 10:40:28 · 215 阅读 · 0 评论 -
PAT2019春7-2 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-09-04 17:06:58 · 129 阅读 · 0 评论 -
PAT2019春7-1 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:原创 2020-09-04 16:19:36 · 391 阅读 · 0 评论 -
PAT2019秋7-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-09-04 15:44:16 · 486 阅读 · 0 评论 -
PAT (Advanced Level)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原创 2020-09-04 14:27:13 · 164 阅读 · 0 评论 -
PAT2019秋7-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原创 2020-09-04 14:38:17 · 254 阅读 · 0 评论 -
PAT2019秋7-2 Merging Linked Lists (25 分)
Given two singly linked listsL1=a1→a2→⋯→an−1→anandL2=b1→b2→⋯→bm−1→bm. Ifn≥2m, you are supposed to reverse and merge the shorter one into the longer one to obtain a list likea1→a2→bm→a3→a4→bm−1⋯. For exam...原创 2020-09-04 12:48:01 · 629 阅读 · 0 评论 -
PAT2019秋7-1 Forever (20 分)
"Forever number" is a positive integerAwithKdigits, satisfying the following constrains:the sum of all the digits ofAism; the sum of all the digits ofA+1isn; and the greatest common divisor ofmandnis a prime number which is greater than 2...原创 2020-09-04 11:25:18 · 140 阅读 · 0 评论 -
PAT(甲级)2020年春季考试7-4 Replacement Selection (30分)
When the input is much too large to fit into memory, we have to doexternal sortinginstead of internal sorting. One of the key steps in external sorting is to generate sets of sorted records (also calledruns) with limited internal memory. The simplest me...原创 2020-09-04 08:38:51 · 293 阅读 · 0 评论 -
PAT(甲级)2020年春季考试7-3 Safari Park (25分)
A safari park(野生动物园)hasKspecies of animals, and is divided intoNregions. 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-09-03 23:55:37 · 163 阅读 · 0 评论 -
PAT(甲级)2020年春季考试7-2 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-09-03 22:26:52 · 233 阅读 · 0 评论 -
PAT(甲级)2020年春季考试7-1 Prime Day (20分)
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 date20190523is a prime, but all its sub-strings ended at the last digit3are prime numbers.Now your job i...原创 2020-09-03 21:36:56 · 149 阅读 · 0 评论 -
PAT (Advanced Level)1018 Public Bike Management (30分)
There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the city.The Public Bike Management Center (PBMC) keeps mo原创 2020-09-03 17:26:29 · 93 阅读 · 0 评论 -
PAT (Advanced Level)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原创 2020-09-02 21:16:48 · 89 阅读 · 0 评论 -
PAT (Advanced Level)1045 Favorite Color Stripe (30分)
Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts together to form her favorite color stripe.It is said原创 2020-09-02 17:16:41 · 90 阅读 · 0 评论 -
PAT (Advanced Level)1040 Longest Symmetric String (25分)
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, givenIs PAT&TAP symmetric?, the longest symmetric sub-string iss PAT&TAP s, hence you must output11.Input Specification:Each input file c...原创 2020-09-02 15:03:26 · 82 阅读 · 0 评论 -
PAT (Advanced Level)1007 Maximum Subsequence Sum (25分)
Given a sequence ofKintegers {N1,N2, ...,NK}. A continuous subsequence is defined to be {Ni,Ni+1, ...,Nj} where1≤i≤j≤K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For exampl...原创 2020-09-02 14:30:02 · 97 阅读 · 0 评论 -
PAT (Advanced Level)1119 Pre- and Post-order Traversals (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, or preorder and inorder traversal sequences. However, if only the postorder and原创 2020-09-02 13:52:41 · 109 阅读 · 0 评论 -
PAT (Advanced Level)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 th原创 2020-09-02 09:52:01 · 112 阅读 · 0 评论 -
PAT (Advanced Level)1094 The Largest Generation (25分)
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 Specification:Each input file contains one test case.原创 2020-09-01 20:20:19 · 113 阅读 · 0 评论 -
PAT (Advanced Level)1090 Highest 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 pricePa..原创 2020-09-01 17:21:26 · 81 阅读 · 0 评论 -
PAT (Advanced Level)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(原创 2020-09-01 16:22:25 · 83 阅读 · 0 评论 -
PAT (Advanced Level)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 the chain buys products from one's supplier in a pricePa..原创 2020-09-01 11:18:49 · 93 阅读 · 0 评论 -
7-3 垃圾分类 (20分)
据香港《南华早报》2019年7月15日文章,上海严格的垃圾分类新规令不少居民抓狂。这催生出大量帮助找出正确分类答案的App和小程序。目前仅微信上就至少有280种与垃圾处理有关的App,在苹果应用商店也达130种。支付宝表示,已有60多家独立App开发商申请为该平台提供类似服务。本题就请你现场实现一个简单的垃圾分类小助手。输入格式:输入首先给出官方分类指南中每种物品的归属。在一行中给出一个正整数 N(≤105),即物品数量;随后 N 行,每行给出一个物品名称(长度不超过 10 的、由小写英文原创 2020-09-01 09:42:59 · 232 阅读 · 0 评论 -
7-2 三阶幸福数 (20分)
对一个十进制数的各位数字做一次立方和,称作一次迭代。如果一个十进制数能通过h次迭代得到 1,就称该数为三阶幸福数,迭代的次数h称为幸福度。例如 1579 经过 1 次迭代得到 1198,2 次迭代后得到 1243,3 次迭代后得到 100,最后得到 1。则 1579 是幸福数,其幸福度为 4。另一方面,如果一个大于1的数字经过数次迭代后进入了死循环,那这个数就不幸福。例如 97 迭代得到 1072、352、160、217、352、…… 可见 352 到 217 形成了死循环,所以 97 就不幸福...原创 2020-09-01 09:40:34 · 313 阅读 · 0 评论 -
7-1 Knuth洗牌法 (20分)
Knuth 洗牌法是生成 { 1, 2, ..., n } 的一个随机重排列的算法。与每次反复随机生成一个数字,直到获得一个不重复的新数字的算法不同,Knuth 洗牌法从原始序列 { 1, 2, ..., n } 开始,逐次洗牌。洗牌的方法是从左到右,每轮从没确定的数字中随机抽取一个数,把它放到确定的位置上。例如令 n 等于 4。我们从 { 1, 2, 3, 4 } 开始。记 i 到 N 之间的随机抽牌数为random(i,N)。假设我们生成的随机数序列 random(i,4) (i=1, 2, 3,.原创 2020-09-01 09:38:52 · 180 阅读 · 0 评论 -
PAT (Advanced Level)1076 Forwards on Weibo (30分)
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, all his/her followers can vi原创 2020-08-29 18:46:42 · 71 阅读 · 0 评论 -
PAT2019年冬7-4 Cartesian Tree (30分)
ACartesian treeis 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 }, the min-heap Cartesia..原创 2020-08-29 16:55:39 · 83 阅读 · 0 评论 -
PAT2019年冬7-3 Summit (25分)
Asummit(峰会) 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 a set of tentati..原创 2020-08-29 16:54:33 · 108 阅读 · 0 评论 -
PAT2019年冬7-2 Block Reversing (25分)
Given a singly linked listL. Let us consider everyKnodes as ablock(if there are less thanKnodes 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 inL. For example, givenLas 1→2→3...原创 2020-08-29 16:52:56 · 107 阅读 · 0 评论 -
PAT2019年冬7-1 Good in C (20分)
When your interviewer asks you to write "Hello World" using C, can you do as the following figure shows?Input Specification:Each input file contains one test case. For each case, the first part gives the 26 capital English letters A-Z, each in a7×5..原创 2020-08-29 16:51:45 · 88 阅读 · 0 评论 -
PAT (Advanced Level)1021 Deepest Root (25分)
A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root is calledthe deepest root.Input Specification:Each .原创 2020-08-28 13:24:22 · 70 阅读 · 0 评论 -
PAT (Advanced Level)1013 Battle Over Cities (25分)
It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any other highways to keep the rest of the c原创 2020-08-28 11:58:18 · 76 阅读 · 0 评论 -
PAT (Advanced Level)1034 Head of a Gang (30分)
One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call betweenAandB, we say thatAandBis related. The weight of a relation is defined to be the total time length of all the phone calls made between...原创 2020-08-28 08:14:31 · 76 阅读 · 0 评论 -
PAT (Advanced Level)1073 Scientific Notation (20分)
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 integer portion has exactly one digit, there is at least one原创 2020-08-25 17:09:37 · 118 阅读 · 0 评论 -
PAT (Advanced Level)1043 Is It a Binary Search Tree (25分)
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 th原创 2020-08-25 11:30:25 · 77 阅读 · 0 评论 -
PAT (Advanced Level)1025 PAT Ranking (25分)
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your原创 2020-08-25 10:03:24 · 79 阅读 · 0 评论 -
PAT (Advanced Level)1057 Stack (30分)
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). Now you are supposed to im原创 2020-08-24 21:10:43 · 88 阅读 · 0 评论