PAT甲级
PAT甲级详细题解C++版
zhb1nk
字节跳动前端工程师
展开
-
PAT 甲级 1139 First Contact (30 分)【模拟好题】
Unlike in nowadays, the way that boys and girls expressing their feelings of love was quite subtle in the early years. When a boy A had a crush on a girl B, he would usually not contact her directly i...原创 2019-05-19 09:42:35 · 693 阅读 · 0 评论 -
PAT甲级 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....原创 2019-05-18 19:55:53 · 387 阅读 · 0 评论 -
PAT 甲级 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 adj...原创 2019-05-18 12:31:18 · 214 阅读 · 0 评论 -
PAT甲级 1143 Lowest Common Ancestor (30 分)【LCA】
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 t...原创 2019-05-18 11:32:15 · 246 阅读 · 0 评论 -
PAT甲级 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...原创 2019-05-18 08:57:17 · 233 阅读 · 0 评论 -
PAT甲级 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 sea...原创 2019-05-17 22:12:50 · 329 阅读 · 0 评论 -
PAT甲级 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...原创 2019-05-17 21:18:35 · 450 阅读 · 0 评论 -
PAT 甲级 1103 Integer Factorization
PTA | 程序设计类实验辅助教学平台题目大意:给顶正整数N、K、P,将N表示成K个正整数(可以相同,递减排列)的P次方的和思路:首先求出所有不同底数时P次幂的数,存在fac[]中枚举fac数组,对于每个元素可多次选取#include <iostream>#include <vector>#include <cmath>using namespa...原创 2019-03-22 23:28:39 · 225 阅读 · 0 评论 -
PAT甲级 1034 Head of a Gang
https://pintia.cn/problem-sets/994805342720868352/problems/994805456881434624One way that the police finds the head of a gang is to check people’s phone calls. If there is a phone call between### Aan...原创 2019-03-21 21:52:45 · 211 阅读 · 0 评论 -
PAT 甲级 1154 Vertex Coloring 【图的遍历】
题意:给出图和图上每个点的颜色,问是否满足 图上所有边的两个端点的颜色不相同#include <iostream>#include <cstring>#include <set>#include <vector>using namespace std;const int maxn = 10010;int N, M, K;set&l...原创 2019-03-01 15:19:10 · 241 阅读 · 0 评论 -
PAT甲级 1021 Deepest Root 图的遍历
题目链接:PTA | 程序设计类实验辅助教学平台题意:求树的最大深度最后一行for (vector&amp;amp;amp;amp;lt;int&amp;amp;amp;amp;gt;::iterator it = nodes.begin(); it!=nodes.end(); ++ it) cout &amp;amp;amp;amp;lt;&amp;amp;amp;amp;lt; *it &amp;amp;amp;amp原创 2019-03-01 13:56:17 · 262 阅读 · 0 评论 -
PAT 甲级 1106 Lowest Price in Supply Chain 图的遍历
https://pintia.cn/problem-sets/994805342720868352/problems/994805362341822464题目大意:在一颗树里找叶子结点的最小深度 和 这个深度上的叶子结点个数为什么AC不了呢,有人可以帮我看一下么#include &lt;iostream&gt;#include &lt;vector&gt;#include &lt;c...原创 2019-02-28 17:48:24 · 189 阅读 · 0 评论 -
PAT 甲级 Tree Traversals 后序遍历+中序遍历建树
题意:由后序、中序遍历构造出二叉树,输出层序遍历建树思路:后序遍历:“左右根”,后序序列的最后一个元素一定是整棵树的根,从后向前,能分别找到右、左子树的根,通过后序序列可以找到一系列的根。中序遍历:“左根右”,在中序序列中定位出根的位置,根左边的一定是左子树,右边的一定是右子树。所以每次都是先通过后续遍历,找到根节点,再通过中序遍历,找到左子树和右子树。建好树后通过BFS输出层序遍历...原创 2019-02-27 19:42:31 · 619 阅读 · 3 评论 -
PAT 甲级 Reversible Primes
如果一个数是素数,那么它在任何进制下都是素数#include <iostream>#include <algorithm>#include <cmath>using namespace std;int n, k;bool isprime(int num){ if (num == 0 || num == 1) return false;...原创 2019-02-27 11:19:44 · 170 阅读 · 0 评论 -
PAT 甲级 Battle Over Cities 图遍历 并查集
PTA | 程序设计类实验辅助教学平台找到连通分量的个数需要添加的道路数是连通分量个数-1找连通分量可以遍历也可以并查集dfs遍历图#include &lt;iostream&gt;#include &lt;algorithm&gt;#include &lt;cstring&gt;#include &lt;vector&gt;using namespace s原创 2019-02-27 10:07:37 · 199 阅读 · 0 评论 -
PAT甲级 Emergency 堆优化dijkstra最短路径条数问题
题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805523835109376堆优化dijkstra加两个数组,tot[i]记录起点到i最短路径条数sum[i]记录起点到i最大人数用点head松弛点v (比较v到原点距离 与 (head到原点距离 + v与head距离)) 时如果v到起点的距离与hea...原创 2019-02-26 18:59:42 · 254 阅读 · 0 评论 -
PAT甲级 1037 Magic Coupon
https://pintia.cn/problem-sets/994805342720868352/problems/994805451374313472正负数都分别按绝对值降序排一直是这么觉得的:vector + 指针索引 = queuesort + queue = priority_queue#include &lt;iostream&gt;#include &lt;queue&...原创 2019-02-24 16:01:50 · 174 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1001 A+B Format (20 分)
Calculate a+b and output the sum in standard format – that is, the digits must be separated into groups of three by commas (unless there are less than four digits).Input Specification:Each input fil...原创 2019-02-14 22:18:29 · 185 阅读 · 0 评论 -
PAT甲级 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: ...原创 2019-05-17 14:59:45 · 231 阅读 · 0 评论 -
PAT甲级 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 (氧化剂)...原创 2019-05-17 10:47:56 · 228 阅读 · 0 评论 -
PAT甲级 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 retu...原创 2019-05-17 10:27:47 · 281 阅读 · 0 评论 -
PAT甲级 1151 LCA in a Binary Tree (30 分) 【LCA】
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.Inpu...原创 2019-05-16 19:21:35 · 252 阅读 · 0 评论 -
PAT甲级 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 p...原创 2019-05-16 17:38:12 · 395 阅读 · 0 评论 -
PAT甲级 1153 Decode Registration Card of PAT 【字符串模拟】
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 numb...原创 2019-05-16 15:55:04 · 244 阅读 · 0 评论 -
PAT甲级 1155 Heap Paths【堆 dfs】
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 (i...原创 2019-05-16 10:46:58 · 193 阅读 · 0 评论