—— AC笔记 ——
文章平均质量分 60
LeetCode
_之桐_
一万年太久,只争朝夕,为博学而专精。
展开
-
AC笔记 | 1455. 检查单词是否为句中其他单词的前缀
检查单词是否为句中其他单词的前缀原创 2022-08-21 11:02:15 · 162 阅读 · 0 评论 -
AC笔记 | 领扣Java容器脚手架
List:ArrayList和LinkedListQueue:LinkedListStack:LinkedListMap:HashMapSet:HashSet原创 2022-08-07 17:42:42 · 152 阅读 · 0 评论 -
【PAT】A1034 Head of a Gang(图的DFS) ***
One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call betweenAandB, we say thatAandBis related. The weight of a relation is defined to be t...原创 2019-08-22 16:30:07 · 117 阅读 · 0 评论 -
【PAT】A1074 Reversing Linked List ***
Given a constantKand a singly linked listL, you are supposed to reverse the links of everyKelements onL. For example, givenLbeing 1→2→3→4→5→6, ifK=3, then you must output 3→2→1→6→5→4; ifK=4, ...原创 2019-08-13 15:34:17 · 107 阅读 · 0 评论 -
【堆】堆的基本操作总结
堆:大顶堆:根结点比左右子树更大;小顶堆:根节点比左右子树更小。定义一个堆: const int main=100;//heap为堆,n为元素个数int heap[maxn],n=10; 调整堆: //在heap数组在[low,high]范围进行向下调整//其中low为欲调整的结点的数组下标,high一般为堆的最后一个元素的数组下标void downAdj...原创 2019-08-21 16:36:24 · 223 阅读 · 0 评论 -
【PAT】A1039 Course List for Student
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 com...原创 2019-08-01 16:40:11 · 345 阅读 · 0 评论 -
【PAT】A1100 Mars Numbers *
People on Mars count their numbers with base 13:Zero on Earth is called "tret" on Mars. The numbers 1 to 12 on Earth is called "jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" on Mars, ...原创 2019-08-03 16:22:35 · 146 阅读 · 0 评论 -
【PAT】A1028 List Sorting
Input Specification:Each input file contains one test case. For each case, the first line contains two integersN(≤105) andC, whereNis the number of records andCis the column that you are s...原创 2019-07-31 17:05:45 · 229 阅读 · 0 评论 -
【PAT笔记】数学问题——分数的四则运算
分数的四则运算是从小学开始接触,运算规则和原理大家应该都很清楚了。我们现在要做的就是如何通过程序,让计算机来做分数的四则运算。1 分数的表示首先来表示一个分数,最简单的就是用假分数表示了,也就是无论分子比分母大还是比分母小,都保留原数。那么就可以通过设置一个结构体来存储这种只有分子和分母的分数了。struct Fraction{ int up,down;};2 分数的化...原创 2019-03-03 16:32:51 · 1263 阅读 · 0 评论 -
【PAT】A1054 The Dominant Color
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 th...原创 2019-08-03 17:03:05 · 106 阅读 · 0 评论 -
【PAT】A1047 Student List for Course
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 S...原创 2019-08-01 16:57:09 · 129 阅读 · 0 评论 -
【PAT】A1066 Root of AVL Tree ***
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...原创 2019-08-16 17:20:33 · 133 阅读 · 0 评论 -
【PAT】A1083 List Grades
Given a list ofNstudent 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-07-31 17:00:33 · 114 阅读 · 0 评论 -
【PAT】A1055 The World‘s Richest
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-07-30 16:42:56 · 139 阅读 · 0 评论 -
【PAT】A1097 Deduplication on a Linked List
Given a singly linked listLwith integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each valueK, only the first node of which the value or a...原创 2019-08-11 17:02:21 · 127 阅读 · 0 评论 -
【PAT】A1043 Is It a Binary Search Tree **
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 su...原创 2019-08-15 16:18:23 · 111 阅读 · 0 评论 -
【2019暑假刷题笔记-树的遍历】总结
关于树这一块,前期没有做一个学习的绪论,因为时间来不及了。在总结上回顾一下这些题目的一些特点 树的遍历的是数据结构树这一块中的一部分。 树的遍历和二叉树的遍历本质上相同。二叉树用指针也可以做,但是在考试中用静态数组处理树更有优势 树的遍历一般的模板是:输入——递归(设置边界-递归两步)——输出 输入形式的代码: for(int i=0;i<prese...原创 2019-08-14 17:12:02 · 163 阅读 · 0 评论 -
【PAT】A1056 Mice and Rice *
Mice and Riceis the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of each mouse is to eat as much rice...原创 2019-08-07 15:41:41 · 149 阅读 · 0 评论 -
【PAT】A1004 Counting Leaves
A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file contains one test case. Each case starts...原创 2019-08-14 16:34:50 · 136 阅读 · 0 评论 -
【PAT】A1071 Speech Patterns *
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-08-04 15:54:31 · 142 阅读 · 0 评论 -
【PAT】A1080 Graduate Admission
It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission...原创 2019-07-31 16:52:05 · 131 阅读 · 0 评论 -
【PAT】A1099 Build A Binary Search Tree
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...原创 2019-08-16 14:58:41 · 143 阅读 · 0 评论 -
【栈】栈的基本操作实现模板的总结
一、栈的应用栈是一种先进后出(FILO)的数据结构 清空(clear): /*栈的清空操作就是把栈顶top置为-1*/void clear(){ top=-1;}/*清空栈,由于没有直接用于清空栈的元素,所以使用while和pop组合*/while(!st.size()) st.pop(); 获取栈内元素个数(size): /*由于栈顶指针t...原创 2019-08-05 17:18:51 · 296 阅读 · 0 评论 -
【PAT】A1090 Highest Price in Supply Chain
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 th...原创 2019-08-13 16:30:21 · 91 阅读 · 0 评论 -
【并查集】并查集的基本操作总结
并查集的定义:“并”,Union(合并);“查”,Find(查找);“集”,Set(查找);并查集的实现: int father[N]; //使用一个数组记录father[1]=1; //1的父节点是本身father[2]=1; //2的父节点是1 并查集的初始化: for(int i=1;i<=n;i++){ father[i]=i;} ...原创 2019-08-21 14:36:48 · 242 阅读 · 1 评论 -
【PTA】JAVA提交的一些注意点
在PTA提交Java程序需要注意如下几个要点:文章目录0. 不要包含package关键字1. Main类与Scanner1.1 Main类1.2 使用Scanner处理输入2.Scanner对象常用方法3.字符串与整型互相转换4.Scanner常见问题5.输出5.1 `System.out.println("abc")`打印字符串"abc"并回车换行。可使用`+`号连接各个类型的变量,组装成字符...转载 2020-05-05 16:14:58 · 3636 阅读 · 1 评论 -
【PAT】A1051 Pop Sequence
Given a stack which can keepMnumbers at most. PushNnumbers in the order of 1, 2, 3, ...,Nand pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of t...原创 2019-08-06 15:24:31 · 170 阅读 · 0 评论 -
【PAT】A1094 The Largest Generation
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 ...原创 2019-08-13 17:21:05 · 142 阅读 · 0 评论 -
【PAT】A1086 Tree Traversals Again
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-08-12 15:40:24 · 136 阅读 · 0 评论 -
【PAT】B1048 数字加密
题目描述本题要求实现一种数字加密方法。首先固定一个加密用正整数 A,对任一正整数 B,将其每 1 位数字与 A 的对应位置上的数字进行以下运算:对奇数位,对应位的数字相加后对 13 取余——这里用 J 代表 10、Q 代表 11、K 代表 12;对偶数位,用 B 的数字减去 A 的数字,若结果为负数,则再加 10。这里令个位为第 1 位。输入格式:输入在一行中依次给出 A 和 B...原创 2019-01-28 22:20:37 · 320 阅读 · 0 评论 -
【PAT笔记】C++标准模板库STL(一)——vector的用法和示例
1.vector的常见用法vector翻译为向量,但是用“长短根据需要而自动改变的数组”更容易记忆。如果要使用vector,则需要用到头文件#include <vector>,另外还需要using namespace std; 才可以使用。PAT中的相关题目有(代码见下方):1039 Course List for Student (25 分)1047 Student ...原创 2019-02-14 22:44:51 · 451 阅读 · 0 评论 -
【PAT】A1060 Are They Equal *
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 signif...原创 2019-08-03 13:21:46 · 128 阅读 · 0 评论 -
【PAT】A1079 Total Sales of Supply Chain
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...原创 2019-08-13 15:39:03 · 235 阅读 · 0 评论 -
【PAT】A1107 Social Clusters ***
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. Asocial clusteris a set of people who have some of t...原创 2019-08-21 15:55:30 · 109 阅读 · 0 评论 -
【PAT笔记】PAT中的散列思想
散列的介绍散列(hash)是常用的算法思想之一,在很多程序上都会有意无意的使用到。用一句话来概括散列思想的话就是:“将元素通过一个函数转换为整数,使得该整数可以尽量唯一地代表这个元素”。其中把转换函数称为散列函数H。那么对key是整数来说,有哪些常用的散列函数呢?一般来说,常见的散列函数有直接定址法、平方取中法、除留余数法,其中直接定址法是指恒等变换(即H(key)=key,很多问题都是直...原创 2019-02-02 00:04:01 · 246 阅读 · 0 评论 -
【2019暑假刷题笔记-STL绪论(二)】总结自《算法笔记》
目录五、queue的常见用法六、priority_queue的常见用法七、stack的常见用法八、algorithm头文件下的常用函数五、queue的常见用法queue也就是队列,是STL中实现先进先出的容器。queue是在当需要实现BFS的时候,可以不用自己去手动实现一个队列,而是用queue作为代替,提高代码的准确性。另外要注意的一点是,在使用front()和back(...原创 2019-08-05 17:02:33 · 161 阅读 · 0 评论 -
【PAT】A1098 Insertion or Heap Sort
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,...原创 2019-08-21 17:15:11 · 196 阅读 · 0 评论 -
【PAT】A1053 Path of Equal Weight
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 fro...原创 2019-08-13 14:19:19 · 138 阅读 · 0 评论 -
【PAT】A1063 Set Similarity
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 ...原创 2019-08-02 14:33:48 · 146 阅读 · 0 评论 -
【PAT笔记】数学问题——素数和质因数
1 素数1.1 素数的判断素数的判断较为简单,直接上代码,需要注意的几点:bool isPrime(int n){ if(n==1) return false; //1需要特判 int sqr=(int)sqrt(n*1.0); //之所以要用这条语句而不是在for循环里使用sqrt(n),解释如下 for(int i=2;i<=sqr...原创 2019-03-05 15:47:54 · 497 阅读 · 0 评论