PAT甲级
rnzhiw
技术使人成长
展开
-
1113 Integer Set Partition (25 分) 排序
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 all the numbers in...原创 2019-12-04 10:50:51 · 282 阅读 · 0 评论 -
1108 Finding Average (20 分)字符串处理(sscanf和sprintf)
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...原创 2019-12-02 18:31:25 · 245 阅读 · 0 评论 -
1107 Social Clusters (30 分) 并查集
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...原创 2019-12-02 18:19:37 · 187 阅读 · 0 评论 -
1106 Lowest Price in Supply Chain (25 分) DFS
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...原创 2019-12-01 15:37:29 · 118 阅读 · 0 评论 -
1104 Sum of Number Segments (20 分) 数学问题
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...原创 2019-12-01 15:27:17 · 126 阅读 · 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 pr...原创 2019-12-01 15:24:56 · 135 阅读 · 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 subt...原创 2019-12-01 15:06:08 · 380 阅读 · 0 评论 -
1095 Cars on Campus (30 分) 排序
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...原创 2019-12-01 14:39:40 · 132 阅读 · 0 评论 -
1094 The Largest Generation (25 分) DFS
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 S...原创 2019-12-01 14:31:56 · 152 阅读 · 0 评论 -
1092 To Buy or Not to Buy (20 分) hash散列
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...原创 2019-12-01 14:00:14 · 137 阅读 · 0 评论 -
1090 Highest Price in Supply Chain (25 分)DFS
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...原创 2019-12-01 13:41:10 · 126 阅读 · 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 stac...原创 2019-12-01 13:18:50 · 192 阅读 · 0 评论 -
1084 Broken Keyboard (20 分) hash散列
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 ...原创 2019-12-01 11:36:01 · 147 阅读 · 0 评论 -
1083 List Grades (25 分) 排序
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 ...原创 2019-12-01 10:39:30 · 177 阅读 · 0 评论 -
1079 Total Sales of Supply Chain (25 分) DFS
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...原创 2019-12-01 10:07:34 · 137 阅读 · 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 be H(key)=key%TSiz...原创 2019-11-30 21:33:51 · 110 阅读 · 0 评论 -
1077 Kuchiguse (20 分) 字符串处理
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 ...原创 2019-11-30 16:46:38 · 465 阅读 · 0 评论 -
1076 Forwards on Weibo (30 分) BFS
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 ...原创 2019-11-29 23:12:21 · 124 阅读 · 0 评论 -
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 intege...原创 2019-11-28 17:22:54 · 186 阅读 · 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...原创 2019-11-28 17:15:37 · 161 阅读 · 0 评论 -
1070 Mooncake (25 分)贪心算法 分月饼
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 ...原创 2019-11-28 16:44:38 · 855 阅读 · 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 takin...原创 2019-11-27 11:58:01 · 135 阅读 · 0 评论 -
1068 Find More Coins (30 分) 01背包,动态规划
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,...原创 2019-11-27 11:39:42 · 118 阅读 · 0 评论 -
1065 A+B and C (64bit) (20 分) 大整数比较
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). Then T ...原创 2019-11-27 11:23:23 · 167 阅读 · 0 评论 -
1063 Set Similarity (25 分) set集合
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 distinct nu...原创 2019-11-27 10:47:24 · 124 阅读 · 0 评论 -
1062 Talent and Virtue (25 分) 排序
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...原创 2019-11-24 13:39:33 · 167 阅读 · 0 评论 -
1058 A+B in Hogwarts (20 分) 进制转换
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 Sic...原创 2019-11-24 12:44:08 · 105 阅读 · 0 评论 -
1055 The World's Richest (25 分) 排序
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 peopl...原创 2019-11-24 12:30:28 · 256 阅读 · 0 评论 -
1054 The Dominant Color (20 分) map集合
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 d...原创 2019-11-23 21:15:01 · 189 阅读 · 0 评论 -
1053 Path of Equal Weight (30 分) dfs,树
Given a non-empty tree with root R, and with weight Wi assigned to each tree node Ti. The weight of a path from R to L is defined to be the sum of the weights of all the nodes along the path from R t...原创 2019-11-23 20:06:55 · 107 阅读 · 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 integer key and a Next pointer to the next structure. Now give...原创 2019-11-23 19:24:34 · 148 阅读 · 0 评论 -
1051 Pop Sequence (25 分) 模拟栈
Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, …, N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the...原创 2019-11-23 18:39:29 · 156 阅读 · 0 评论 -
1050 String Subtraction (20 分) 字符串处理
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking all the characters in S2 from S1. Your task is simply to calculate S1−S2 for any given strings. However, it mi...原创 2019-11-22 16:46:38 · 210 阅读 · 0 评论 -
1048 Find Coins (25 分) hash散列
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,...原创 2019-11-20 18:12:22 · 144 阅读 · 0 评论 -
1047 Student List for Course (25 分) 排序,vector的使用
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 Sp...原创 2019-11-20 17:51:23 · 243 阅读 · 0 评论 -
1046 Shortest Distance (20 分) 环中两点的最短路径
The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.Input Specification:Each input file contain...原创 2019-11-20 16:47:30 · 197 阅读 · 0 评论 -
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...原创 2019-11-20 16:17:29 · 130 阅读 · 0 评论 -
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 subt...原创 2019-11-20 11:43:38 · 180 阅读 · 0 评论 -
1041 Be Unique (20 分) hash输出第一个出现只出现一次的数字
Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1,10^4]. The first one who bets o...原创 2019-11-20 10:09:11 · 95 阅读 · 0 评论 -
1040 Longest Symmetric String (25 分) 动态规划求字符串最大回文子串长度
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?, the longest symmetric sub-string is s PAT&TAP s, hence you ...原创 2019-11-19 22:24:57 · 118 阅读 · 0 评论