PAT_甲级_1007 Maximum Subsequence Sum

2020-12-08
阅读 4 分钟
1.2k
如上图所示,实际上该问题,等价与初始和为0,取得每一个数字作为起点的所有子序列和的最大值中的最大值,如图中所标注的20.直接使用深度优先搜索解决。代码如下:

PAT(甲级)2020年秋季考试 7-4 Professional Ability Test

2020-12-06
阅读 7 分钟
2.3k
Professional Ability Test (PAT) consists of several series of subject tests. Each test is divided into several levels. Level A is a prerequisite (前置要求) of Level B if one must pass Level A with a score no less than S in order to be qualified to take Level B. At the mean time, one who passes Le...

PAT(甲级)2020年秋季考试 7-2 How Many Ways to Buy a Piece of Land

2020-12-06
阅读 2 分钟
1.6k
The land is for sale in CyberCity, and is divided into several pieces. Here it is assumed that each piece of land has exactly two neighboring pieces, except the first and the last that have only one. One can buy several contiguous(连续的) pieces at a time. Now given the list of prices of the la...

PAT(甲级)2020年秋季考试 7-1 Panda and PP Milk

2020-12-06
阅读 4 分钟
2.2k
PP milk (盆盆奶)is Pandas' favorite. They would line up to enjoy it as show in the picture. On the other hand, they could drink in peace only if they believe that the amount of PP milk is fairly distributed, that is, fatter panda can have more milk, and the ones with equal weight may have the s...

PAT(甲级)2020年秋季考试 7-3 Left-View of Binary Tree

2020-12-06
阅读 3 分钟
1.6k
The left-view of a binary tree is a list of nodes obtained by looking at the tree from left hand side and from top down. For example, given a tree shown by the figure, its left-view is { 1, 2, 3, 4, 5 }

PAT(甲级)2020年春季考试 7-4 Replacement Selection

2020-12-04
阅读 5 分钟
2.4k
When the input is much too large to fit into memory, we have to do external sorting instead of internal sorting. One of the key steps in external sorting is to generate sets of sorted records (also called runs) with limited internal memory. The simplest method is to read as many records as possib...

PAT(甲级)2020年春季考试 7-2 The Judger

2020-12-04
阅读 6 分钟
2k
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 must not be duplicated to any of the existe...

PAT(甲级)2020年春季考试 7-3 Safari Park

2020-12-03
阅读 4 分钟
1.7k
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 problem, you are not expected to solve ...

PAT(甲级)2020年春季考试 7-1 Prime Day

2020-12-03
阅读 2 分钟
1.3k
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.

PAT(甲级)2019年秋季考试 7-4 Dijkstra Sequence

2020-12-03
阅读 4 分钟
1.6k
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 by computer scientist Edsger W. Dijkstra...

PAT(甲级)2019年秋季考试 7-3 Postfix Expression

2020-12-03
阅读 3 分钟
1.2k
Given a syntax tree (binary), you are supposed to output the corresponding postfix expression, with parentheses reflecting the precedences of the operators.

PAT(甲级)2019年秋季考试 7-2 Merging Linked Lists

2020-12-03
阅读 4 分钟
1.9k
Given two singly linked lists L​1​​=$a​_1$​​→$a​_2$→⋯→$a​_{n-1}$​​→$a​_n$​​ and L​2​​=$b​_1​​$→$b​_2$​​→⋯→$b​_{m-1}$​​→$b​_m​​$​​. If n≥2m, you are supposed to reverse and merge the shorter one into the longer one to obtain a list like a​1​​→a​2​​→b​m​​→a​3​​→a​4​​→b​m−1​​⋯. For example, given on...

PAT(甲级)2019年秋季考试 7-1 Forever

2020-12-03
阅读 5 分钟
1.7k
"Forever number" is a positive integer A with K digits, satisfying the following constrains:

PAT(甲级)2019年冬季考试 7-4 Cartesian Tree

2020-12-02
阅读 3 分钟
1.1k
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 }, the min-heap Cartesian tree is shown by the figure.

PAT(甲级)2019年冬季考试 7-3 Summit

2020-12-02
阅读 5 分钟
1.1k
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.

PAT(甲级)2019年冬季考试 7-2 Block Reversing

2020-12-02
阅读 3 分钟
1.6k
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→4→5→6→7→8 and K as 3, your output must b...

PAT(甲级)2019年冬季考试 7-1 Good in C

2020-12-02
阅读 6 分钟
1.2k
When your interviewer asks you to write "Hello World" using C, can you do as the following figure shows?

PAT(甲级)2019年春季考试 7-4 Structure of a Binary Tree

2020-12-02
阅读 11 分钟
1.6k
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.

PAT(甲级)2019年春季考试 7-3 Telefraud Detection

2020-12-02
阅读 8 分钟
1.4k
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 records.

PAT(甲级)2019年春季考试 7-2 Anniversary

2020-12-02
阅读 3 分钟
1.2k
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 alumni among all the people who come to the celebration.

PAT(甲级)2019年春季考试 7-1 Sexy Primes

2020-12-02
阅读 3 分钟
1.3k
Sexy primes are pairs of primes of the form (p, p+6), so-named since "sex" is the Latin word for "six". (Quoted from [链接])

PAT_甲级_1153 Decode Registration Card of PAT

2020-12-01
阅读 3 分钟
1.5k
题目大意:给出一组学生的准考证号和成绩,准考证号包含了等级(乙甲顶),考场号,日期,和个人编号信息,并有三种查询方式type1:给出考试等级,找出该等级的考生,按照成绩降序,准考证升序排序type2:给出考场号,统计该考场的考生数量和总得分type3:给出考试日期,查询该日期下所有考场的考试人数,按照人数降序,考...

PAT_甲级_1155 Heap Paths

2020-12-01
阅读 2 分钟
1.3k
给定一颗N个节点的完全二叉树的层次序列,需要输出该树的所有从根节点到叶子节点的路径(优先访问右子树),然后判断是否是堆,如果不是输出Not Heap,否则输出Max Heap或者Min Heap。

PAT_甲级_1154 Vertex Coloring

2020-11-30
阅读 2 分钟
1.1k
我们使用set diff_colors保存每一次输入的每一个顶点,其大小就是不同顶点的个数,然后遍历每一条边,如果出现一条边的2个顶点颜色相同的情况,说明不存在k-coloring,输出No,否则输出diff_colors集合的大小。

PAT_甲级_1152 Google Recruitment

2020-11-30
阅读 1 分钟
965
使用字符串s接受输入的字符串,并枚举每个k位的子串(起始位置从0到L-K),然后再转换成整数,判断是否是素数,如果是就直接输出并退出程序。如果不存在就输出404.

PAT_甲级_1151 LCA in a Binary Tree

2020-11-30
阅读 6 分钟
1.3k
我们借鉴建树的递归过程完成树的部分搜索,如果当前搜索的子树的根节点和查询节点U和V相等,说明其中之一就是祖先,直接保存并返回即可,否则获取U和V是否在左子树或者右子树的标志,如果都在左子树,那么就都往左子树搜索,如果都在右子树,那么就都往右子树搜索,否则说明当前子树的根节点就是U和V的最近公共祖先,直...

PAT_甲级_1148 Werewolf - Simple Version

2020-11-30
阅读 2 分钟
1.4k
已知 N 名玩家中有 2 人扮演狼人角色,有 2 人说的不是实话,有狼人撒谎但并不是所有狼人都在撒谎。要求你找出扮演狼人角色的是哪几号玩家,如果有解,在一行中按递增顺序输出 2 个狼人的编号;如果解不唯一,则输出最小序列解;若无解则输出 No Solution.

PAT_甲级_1150 Travelling Salesman Problem

2020-11-30
阅读 4 分钟
1.1k
给定一个N个顶点和M条边的无向图,K个查询,每一个查询输入长度为n的路径,判断该路径是否是TS cycle或者TS simple cycle并输出题目要求的对应信息。

PAT_甲级_1149 Dangerous Goods Packaging

2020-11-30
阅读 2 分钟
903
首先使用$incompatible$二维数组存储每一个物体的所有不兼容的物体,并使用$incompat$数组记录当前货箱有哪些无法兼容的物品(为true即为不可兼容),然后在每一个需要装箱的货物进行依次装箱的时候,先检查当前物品是否与已经装箱的物品兼容,如果是,那么就将与该物品不兼容的所有物品的$incompat$记录为true,只要在装...

PAT_甲级_1147 Heaps

2020-11-30
阅读 2 分钟
1k
对于完全二叉树可以使用一个数组来保存其层序序列,然后使用函数isMaxHeap和isMinHeap分别判断该完全二叉树是否是大根堆还是小根堆,如果都不是则输出Not Heap,然后再使用postTraverse对该完全二叉树进行后序遍历,访问节点的时候输出节点即可。