PAT (Advanced Level) Practice
文章平均质量分 77
是六六呀yhy521
这个作者很懒,什么都没留下…
展开
-
1030 Travel Plan (30 分)
欢迎大家关注我的微信公众号(听烟柳),里面不定时更新PAT-A/B程序代码~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...原创 2022-03-03 22:54:40 · 81 阅读 · 0 评论 -
1030 Travel Plan (30 分)
欢迎大家关注我的微信公众号(听烟柳),里面会不定时更新PAT-A/B程序代码~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/...原创 2022-03-03 21:58:47 · 61 阅读 · 0 评论 -
1003 Emergency (25 分)
欢迎大家关注我的微信公众号(听烟柳),里面会不定时更新PAT——A/B程序代码As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of...原创 2022-03-03 20:41:28 · 58 阅读 · 0 评论 -
1076 Forwards on Weibo (30 分)
欢迎大家关注我的公众号,不定期分享PAT-A/B代码~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 po...原创 2022-03-02 20:32:05 · 119 阅读 · 0 评论 -
1021 Deepest Root (25 分)
欢迎大家关注我的公众号,里面不定时分享PAT-A/B代码~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 aroot is calledthe deep...原创 2022-03-02 19:49:22 · 92 阅读 · 0 评论 -
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原创 2022-03-02 16:52:33 · 170 阅读 · 0 评论 -
1066 Root of AVL Tree (25 分)
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 done to restore this property. Figures 1-4 illustrate t原创 2022-02-27 20:16:38 · 174 阅读 · 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 th原创 2022-02-27 19:23:14 · 231 阅读 · 0 评论 -
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 contains only nodes with keys greater th原创 2022-02-27 18:55:05 · 267 阅读 · 0 评论 -
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.原创 2022-02-26 23:00:06 · 175 阅读 · 0 评论 -
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..原创 2022-02-26 21:48:43 · 183 阅读 · 0 评论 -
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..原创 2022-02-26 21:19:26 · 63 阅读 · 0 评论 -
1053 Path of Equal Weight (30 分)
Given a non-empty tree with rootR, and with weightWiassigned to each tree nodeTi. Theweight of a path fromRtoLis defined to be the sum of the weights of all the nodes along the path fromRto any leaf nodeL.Now given any weighted tree, you ar...原创 2022-02-26 20:35:23 · 201 阅读 · 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 Specifi原创 2022-02-25 20:18:04 · 429 阅读 · 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(原创 2022-02-25 19:21:25 · 439 阅读 · 0 评论 -
1020 Tree Traversals (25 分)
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tree.Input Specification:Each inpu原创 2022-02-25 17:00:04 · 130 阅读 · 0 评论 -
1091 Acute Stroke (30 分)
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 calculate the volume of the stroke core.Input Specifica原创 2022-02-25 14:43:37 · 84 阅读 · 0 评论 -
1103 Integer Factorization (30 分)
TheK−Pfactorization of a positive integerNis to writeNas the sum of theP-th power ofKpositive integers. You are supposed to write a program to find theK−Pfactorization ofNfor any positive integersN,KandP.Input Specification:Each input ...原创 2022-02-24 17:17:13 · 168 阅读 · 0 评论 -
1052 Linked List Sorting (25 分)
A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integerkeyand aNextpointer to the next structure. Now given a linked list, you are supposed to sort the structures...原创 2022-02-24 09:19:48 · 152 阅读 · 0 评论 -
1032 Sharing (25 分)
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,loadingandbeingare stored as showed in Figure 1....原创 2022-02-23 21:30:10 · 51 阅读 · 0 评论 -
1071 Speech Patterns (25 分)
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's identity, which is useful when validating, for exampl原创 2022-02-20 16:54:30 · 82 阅读 · 0 评论 -
1054 The Dominant Color (20 分)
Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. Astrictlydominant color takes more than..原创 2022-02-20 16:01:39 · 406 阅读 · 0 评论 -
060 Are They Equal (25 分)
If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as0.123×105with simple chopping. Now given the number of significant digits on a machine and two float numbers, you are su..原创 2022-02-20 11:23:29 · 152 阅读 · 0 评论 -
1063 Set Similarity (25 分)
Given two sets of integers, the similarity of the sets is defined to beNc/Nt×100%, whereNcis the number of distinct common numbers shared by the two sets, andNtis the total number of distinct numbers in the two sets. Your job is to calculate the s...原创 2022-02-19 20:02:44 · 108 阅读 · 0 评论 -
1047 Student List for Course (25 分)
Zhejiang University has 40,000 students and provides 2,500 courses. Now given the registered course list of each student, you are supposed to output the student name lists of all the courses.Input Specification:Each input file contains one test case. F原创 2022-02-19 19:26:17 · 55 阅读 · 0 评论 -
1039 Course List for Student (25 分)
Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query.Input Specification:Each input file cont原创 2022-02-19 19:00:06 · 151 阅读 · 0 评论 -
1024 Palindromic Number (25 分)
A number that will be the same when it is written forwards or backwards is known as aPalindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.Non-palindromic numbers can be paired with palindromi.原创 2022-02-13 20:24:18 · 76 阅读 · 0 评论 -
1023 Have Fun with Numbers (20 分)
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a diffe原创 2022-02-13 17:21:33 · 204 阅读 · 0 评论 -
1059 Prime Factors (25 分)
Given any positive integerN, you are supposed to find all of its prime factors, and write them in the formatN=p1k1×p2k2×⋯×pmkm.Input Specification:Each input file contains one test case which gives a positive integerNin the range oflong in...原创 2022-02-12 21:05:51 · 214 阅读 · 0 评论 -
1078 Hashing (25 分)
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 beH(key)=key%TSizewhereTSizeis the maximum size of the hash table. Qua...原创 2022-02-12 19:49:30 · 59 阅读 · 0 评论 -
1015 Reversible Primes (20 分)
Areversible primein any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime.Now given any two positive integersN(<105) an...原创 2022-02-11 22:48:29 · 305 阅读 · 0 评论 -
1088 Rational Arithmetic (20 分)
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 two rational numbers in原创 2022-02-11 21:54:10 · 55 阅读 · 0 评论 -
1081 Rational Sum (20 分)
GivenNrational numbers in the formnumerator/denominator, you are supposed to calculate their sum.Input Specification:Each input file contains one test case. Each case starts with a positive integerN(≤100), followed in the next lineNrational numb...原创 2022-02-11 21:12:40 · 301 阅读 · 0 评论 -
1049 Counting Ones (30 分)
The task is simple: given any positive integer N, you are supposed to count the total number of 1's in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1's in 1, 10, 11, and 12.Input Specification:Each input f原创 2022-02-10 21:51:15 · 365 阅读 · 0 评论 -
1008 Elevator (20 分)
The highest building in our city has only one elevator. A request list is made up withNpositive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to..原创 2022-02-10 21:00:30 · 415 阅读 · 0 评论 -
1069 The Black Hole of Numbers (20 分)
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 taking the second number from the first one. Repeat in this m原创 2022-02-09 20:20:02 · 274 阅读 · 0 评论 -
1093 Count PAT‘s (25 分)
The stringAPPAPTcontains twoPAT'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 given any string, you are supposed to tell the number of...原创 2022-02-09 15:26:24 · 337 阅读 · 0 评论 -
1029 Median (25 分)
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 sequences is defined to be the me原创 2022-02-08 20:38:27 · 325 阅读 · 0 评论 -
1089 Insert or Merge (25 分)
According to Wikipedia:Insertion sortiterates, 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 within the sorted list, a.原创 2022-02-08 20:11:06 · 328 阅读 · 0 评论 -
1085 Perfect Sequence (25 分)
Given a sequence of positive integers and another positive integerp. The sequence is said to be aperfect sequenceifM≤m×pwhereMandmare the maximum and minimum numbers in the sequence, respectively.Now given a sequence and a parameterp, you are s...原创 2022-02-08 16:46:04 · 313 阅读 · 0 评论