PAT算法笔记
算法笔记总结
隔壁de小刘
这个作者很懒,什么都没留下…
展开
-
PAT算法笔记总目录(基于胡凡算法笔记)
PAT入门题1——入门模拟进制转换日期差值PAT入门题2——算法初步排序算法总结C++排序函数原创 2020-06-10 10:24:38 · 785 阅读 · 0 评论 -
PAT2017-2019考点分析
原创 2021-10-06 16:48:35 · 339 阅读 · 0 评论 -
1123 Is It a Complete AVL Tree (30分)
1123 Is It a Complete AVL Tree (30分)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 th原创 2020-07-25 09:43:11 · 118 阅读 · 0 评论 -
并查集例题
题目描述假如已知有n个人和m对好友关系(存于集合r)。如果两个人是直接或间接的好友(好友的好友的好友…),则认为他们属于同一个朋友圈。请写程序求出这n个人里一共有多少个朋友圈。输入输入包含多个测试用例,每个测试用例的第一行包含两个正整数 n、m,1 < = n,m< =100000。接下来有m行,每行分别输入两个人的编号f,t(1 < = f,t < = n),表示f和t是好友。 当n为0时,输入结束,该用例不被处理。输出对应每个测试用例,输出在这n个人里一共有多少个朋友圈转载 2020-07-24 16:34:51 · 225 阅读 · 0 评论 -
1143 Lowest Common Ancestor (30分)
1143 Lowest Common Ancestor (30分)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 the following propertie原创 2020-07-24 15:00:55 · 159 阅读 · 0 评论 -
1123 Is It a Complete AVL Tree(30 分)
1123 Is It a Complete AVL Tree(30 分)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 th转载 2020-07-23 20:34:15 · 124 阅读 · 0 评论 -
1090 Highest Price in Supply Chain (25分)
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 pro原创 2020-07-23 08:35:38 · 126 阅读 · 0 评论 -
PAT A 1120 Friend Numbers (20分)
1120 Friend Numbers (20分)Two integers are called “friend numbers” if they share the same sum of their digits, and the sum is their “friend ID”. For example, 123 and 51 are friend numbers since 1+2+3 = 5+1 = 6, and 6 is their friend ID. Given some numbers,原创 2020-07-20 16:56:16 · 89 阅读 · 0 评论 -
PAT A 7-2 1121 Damn Single (25分)
1121 Damn Single (25分)“Damn Single (单身狗)” is the Chinese nickname for someone who is being single. You are supposed to find those who are alone in a big party, so they can be taken care of.Input Specification:Each input file contains one test case. For原创 2020-07-20 16:44:54 · 182 阅读 · 0 评论 -
PAT甲级7-4 1127 ZigZagging on a Tree (30分)
1127 ZigZagging on a Tree (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. And it is a simple standard routine to print the原创 2020-07-17 16:24:44 · 287 阅读 · 0 评论 -
PAT甲级7-3 1126 Eulerian Path (25分)
算法笔记总目录关键英语单词解释1126 Eulerian Path (25分)In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which starts and ends on the same vertex. They were first discussed by原创 2020-07-17 10:12:01 · 134 阅读 · 0 评论 -
PAT 甲级 7-1 1125 Chain the Ropes (25分)
1125 Chain the Ropes (25分)Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fold two segments into loops and chain them into one piece, as shown by the figure. The resulting chain will be treated as another原创 2020-07-17 08:58:49 · 99 阅读 · 0 评论 -
PAT甲级 2018秋 7-1 1148 Werewolf - Simple Version (20分)
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: “Player #3 is a hum原创 2020-07-15 11:57:42 · 188 阅读 · 0 评论 -
PAT甲级2017冬7-3 1142 Maximal Clique (25分)
算法笔记总目录关键英语单词解释本题代码与PAT甲级2019冬7-3 Summit(1166)除输出不一样外,其他不变。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 ex原创 2020-07-12 10:50:24 · 147 阅读 · 0 评论 -
PAT甲级2018冬7-3 1154 Vertex Coloring (25分)
算法笔记总目录关键英语单词解释1154 Vertex Coloring (25分)A proper vertex coloring is a labeling of the graph’s vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k colors is called a (proper) k-coloring.N原创 2020-07-12 10:29:29 · 102 阅读 · 0 评论 -
PAT甲级2018秋7-4 1151 LCA in a Binary Tree (30分)
算法笔记总目录关键英语单词解释1151 LCA in a Binary Tree (30分)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.Input Speci原创 2020-07-09 17:06:37 · 141 阅读 · 0 评论 -
PAT甲级2018春季7-4 1147 Heaps (30分)
算法笔记总目录关键英语单词解释1147 Heaps (30分)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 (in a max heap) or less原创 2020-07-09 09:21:26 · 161 阅读 · 0 评论 -
PAT甲级2018冬季7-4 1155 Heap Paths(30 分)
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 (in a max heap) or less than or equal to (in a min heap) t原创 2020-07-09 08:25:47 · 146 阅读 · 0 评论 -
PAT甲级2019春季7-4 1159.Structure of a Binary Tree (30 分)
算法笔记总目录关键英语单词解释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 stateme原创 2020-07-07 11:53:14 · 388 阅读 · 1 评论 -
PAT甲级2019秋季7-3 A1163 PostfixExpression (25分)
算法笔记总目录关键英语单词解释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 SpecificationEach input file contains one tes原创 2020-07-07 09:31:59 · 177 阅读 · 0 评论 -
树的遍历汇总
二叉树遍历先序遍历//先序遍历的实现void preorder(node *root){ if(root == NULL){ return;//到达空树,递归边界 } //访问根结点root printf("%d\n",root->data); //访问左子树 preorder(root->lchild); //访问右子树 preorder(root->rchild); }中序遍历//中序遍历的实现void inorder(node *root){原创 2020-07-06 10:43:25 · 122 阅读 · 0 评论 -
PAT甲级2017冬季 7-2 1141 PAT Ranking of Institutions (25)
算法笔记总目录1141 PAT Ranking of Institutions (25分)After each PAT, the PAT Center will announce the ranking of institutions based on their students’ performances. Now you are asked to generate the ranklist.Input Specification:Each input file contains one tes原创 2020-07-04 10:02:23 · 100 阅读 · 0 评论 -
PAT2018秋7-2 1149 Dangerous Goods Packaging(25 分)- 甲级
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 (氧化剂) must not be packed转载 2020-07-03 11:16:20 · 545 阅读 · 0 评论 -
2019 PAT甲级秋季考试7-2 Merging Linked Lists (25 分)
Given two singly linked lists L1=a1→a2→⋯→an−1→an and L2=b1→b2→⋯→bm−1→bm. If n≥2m, you are supposed to reverse and merge the shorter one into the longer one to obtain a list like a1→a2→bm→a3→a4→bm−1⋯. For exam原创 2020-07-03 10:39:16 · 663 阅读 · 1 评论 -
PAT甲级2017秋季1136 A Delayed Palindrome (20分)
1136 A Delayed Palindrome (20分)Non-palindromic numbers can be paired with palindromic ones via a series of operations. First, the non-palindromic number is reversed and the result is added to the original number. If the result is not a palindromic number原创 2020-07-02 22:16:57 · 945 阅读 · 0 评论 -
PAT甲级 2017-2019 第一题 && 字符串专题
英语单词积累PAT-2019年冬季考试-甲级-7-1 Good in C (20分)PAT甲级2019年秋季考试 1160 Forever (20 分)PAT(甲级)2019年春季考试 7-1 Sexy Primes (20 分)PAT(甲级)2018年冬季 1152 Google Recruitment (20分)substr(i,n)截取从i开始n个字符stoi(n) 将字符n转化为整数 //c++11特性PAT(A) – 2018.9.8秋季考试-甲级(1148) 7-1 Werew原创 2020-07-02 10:03:20 · 236 阅读 · 0 评论 -
PAT-2017年冬季考试-甲级-7-1 1140 Look-and-say Sequence (20分)
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. For example, the 2n原创 2020-07-02 09:52:09 · 167 阅读 · 0 评论 -
C/C++万能头文件#include「bits/stdc++.h」
#include <bits/stdc++.h>using namespace std;包含所有头文件 PAT考试支持原创 2020-07-02 09:45:24 · 1193 阅读 · 1 评论 -
PAT(A) -- 2018春季考试-甲级 1144 The Missing Number (20分)
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 a positive integer N (≤10原创 2020-07-02 09:40:12 · 129 阅读 · 0 评论 -
PAT(A) -- 2018.9.8秋季考试-甲级(1148) 7-1 Werewolf (20 分)
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: “Player #3 is a hum转载 2020-06-29 14:16:38 · 634 阅读 · 0 评论 -
C/C++ int、long int 、long long、、 short int 、无符号整型取值范围,代码测试 、C语言无符号整型输出
类型 存储字节 表示范围 无符号范围 大概范围 int / long int 4...原创 2020-06-28 10:28:40 · 1200 阅读 · 0 评论 -
C/C++ 程序计时函数
//clock() 记录此刻时间,差值计算程序用时#include<iostream>#include<cstdlib>#include<ctime> //头文件using namespace std;clock_t t_start,t_end; int main(){ t_start=clock(); //程序开始计时 int ans=1e8; while(ans>0){ ans--; } t_end=clock(); //程原创 2020-06-28 09:45:23 · 326 阅读 · 0 评论 -
PAT(甲级)2019年春季考试 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:Ea原创 2020-06-28 09:32:44 · 420 阅读 · 0 评论 -
PAT 甲级 英语基础
PAT-甲-2019-秋-7-1positive integer 正整数 digits位 greatest common divisor最大公因数f the solution is not unique, output in the ascending order of n.如果解不唯一,则按n的升序输出;原创 2020-06-27 21:42:57 · 678 阅读 · 0 评论 -
PAT A1043 Is It a Binary Search Tree (25分)
A1043 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 con原创 2020-06-25 11:11:04 · 116 阅读 · 0 评论 -
PAT A 1020 Tree Traversals (25分)——给中序和后序求层序
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原创 2020-06-25 10:22:56 · 118 阅读 · 0 评论 -
PAT(甲级)2018年冬季 1152 Google Recruitment (20分)——素数判定
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 prime found in consecutive原创 2020-06-24 10:39:46 · 191 阅读 · 0 评论 -
设置Dev c++支持C++11 特性 以及 [Error] ‘stoi’ was not declared in this scope解决
原因:stoi() 为C++11特性 需要设置Dev支持C++11选择Tools,然后按下图设置原创 2020-06-24 09:46:45 · 1047 阅读 · 0 评论 -
PAT-2019年冬季考试-甲级 7-4 Cartesian Tree (30分)——小根堆的中序遍历求层序遍历
7-4 Cartesian Tree (30分)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原创 2020-06-24 09:10:08 · 500 阅读 · 0 评论 -
PAT甲级2019冬7-3 Summit(1166)(邻接矩阵存储,直接暴力)
PAT-2019年冬季考试-甲级 7-3 Summit (25分) (邻接矩阵存储,直接暴力)7-3 Summit (25分)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 eve原创 2020-06-22 10:25:59 · 463 阅读 · 0 评论