![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
帕特
文章平均质量分 68
CharlieBrownn
八重樱花繁且枝盛,君需记累瓣必偿情。
展开
-
Integer Set Partition (开数组会段错误,用vector就不会-_-b
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 S2denote the sums of al...原创 2018-12-07 13:56:02 · 208 阅读 · 0 评论 -
First Contact(匹配?找朋友系列
A要勾搭B的话,A要找一个同性朋友C,C认识B的同性朋友D,A就能勾搭上(好复杂的人际关系)一开始以为是DFS,后来发现深度最多就4,直接用vector存A的所有同性朋友,然后要勾搭的时候,遍历A的同性盆友和B的同性盆友,如果他俩是盆友,就存进去ANS里面。然后排序。性别的处理就直接看字符串长度,输出的时候不用输出性别就直接去绝对值了。读懂题目就是简单题Unlike in nowadays,...原创 2018-12-02 00:29:55 · 566 阅读 · 0 评论 -
PAT Ranking of Institutions
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 contain...原创 2018-11-30 22:32:14 · 165 阅读 · 0 评论 -
Maximal Clique
最大团:团内的点是相互连通的,并且无法找出另一个节点和团内节点都是联通的。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...原创 2018-11-30 20:07:25 · 248 阅读 · 0 评论 -
Lowest Common Ancestor
二叉搜索树,左子树是最大堆,右子树是最小堆,所以根据先序遍历的特点,大小在查询数字之间的数字就是LCAPAT里关于树的题全部不需要建树 -_-bThe 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 bi...原创 2018-11-30 20:03:47 · 220 阅读 · 0 评论 -
Perfect Sequence(upper_bound
Given a sequence of positive integers and another positive integer p. The sequence is said to be a perfect sequence if M≤m×p where M and m are the maximum and minimum numbers in the sequence, respecti...原创 2018-11-27 22:52:44 · 164 阅读 · 0 评论 -
Reversing Linked List (链表模拟
一般的链表套路,建结构体,然后从头开始找,把地址push进vector里用reverse交换就可以了Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→...原创 2018-11-27 22:32:31 · 158 阅读 · 0 评论 -
Is It A Red-Black Tree
判断一颗树是否是红黑树-_-b首先,红黑树是一棵平衡二叉树,平衡二叉树又是一棵二叉搜索树。简单的说就是左子树中,子节点比父节点小,右子树中,子节点比父节点大。根节点一定是黑节点。先按先序遍历用编号建树,然后判断,子节点与父节点的大小关系、用编号DFS左右子树的黑节点个数是否一样。There is a kind of balanced binary search tree named re...原创 2018-12-04 17:52:24 · 480 阅读 · 0 评论 -
Vertex Cover(图的覆盖
给出一个点集,判断是否是图的覆盖。就是与这些点相连的边是否覆盖了整张图。给每条边编号,Push进相连的点里,按点集标记判断就看以了。A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at least one vertex of the set. Now ...原创 2018-12-04 16:54:25 · 763 阅读 · 0 评论 -
Postorder Traversal(给出先序遍历和中序遍历求后序遍历)
不用建树首先,先序遍历第一个一定是根节点。现在暂时叫它NOW(在先序遍历里的位置)(即当前节点)然后在中序遍历里找到NOW的位置,假设位置下标是POS(中序遍历),那么左边的就是左子树(L ~ POS-1),右边的就是右子树(POS+1 ~ R)。(都是指中序遍历)一开始的范围是0~N-1(L ~ R)遍历左子树:根节点下标是NOW+1(先序遍历),左边界依然是 L , 右边界是POS ...原创 2018-12-02 00:43:54 · 1733 阅读 · 0 评论 -
A Delayed Palindrome(模拟大数加法
要进一位就flag标记一下,然后下一位相加的时候再加1Consider a positive integer N written in standard notation with k+1 digits ai as ak ⋯a1 a0 with 0≤ai <10 for all i and ak >0. Then N i...原创 2018-12-02 00:46:31 · 146 阅读 · 0 评论 -
Stucked Keyboard (字符串,计数,恶心
求键盘怀了哪几个键,用vector存答案,map标记哪些键坏了。一个样例:3aaabbbccccabc输出应该是 aaabbbcccabc 一个键也没有坏反正就是从左往右遍历一遍,记录连续相同的字母的出现次数,不够K次就标记为没有坏,输出时要注意这一点。一开始想的连续K个相同的字母就pop掉,发现不对。其实坏键可以用set存。 On a broken keybo...原创 2018-12-07 13:32:24 · 659 阅读 · 0 评论 -
Pre- and Post-order Traversals(前序后序求中序(不唯一)
给出前序遍历和后序遍历求一个中序遍历并判断是否唯一,如果孩子全在左/右子树上并且没有兄弟节点就会出现不唯一的情况 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 postorde...原创 2018-12-06 19:53:42 · 1341 阅读 · 0 评论 -
Birds in Forest (并查集
不知道为什么用set存才过Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to...原创 2018-12-06 19:51:01 · 213 阅读 · 0 评论 -
PAT 1112~1151
1112字符串处理,求连续相同的字母,用a[i]和a[i-1]判断和计数,注意当cnt==k时要多往前跳一格。标记好的键。输出的时候遍历整个串,坏的键就往前跳k格。1113分割集合,使元素个数之差最小,元素之和之差最大,排序前n/2个一堆,剩下的一堆就行了,要用vector存。1114并查集,不用考虑任何辈分关系!!!把同一个家族的关联起来就可以了,在join的时候把id小的定...原创 2018-12-08 21:58:46 · 253 阅读 · 0 评论 -
Is It a Complete 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 is...原创 2018-12-05 22:47:27 · 149 阅读 · 0 评论 -
sscanf/sprintf
sscanf() – 从一个字符串中读进与指定格式相符的数据sprintf() – 字符串格式化命令,主要功能是把格式化的数据写入某个字符串中sscanf(a, "%lf", &temp);sprintf(b, "%.2lf",temp);当 a=2.555555555555.666tmp=2.55556b=2.56注意:当数据类型为int时,直接取整,不会四舍五...原创 2018-12-08 14:03:28 · 206 阅读 · 0 评论 -
Family Property (并查集,麻烦
This time, you are supposed to help us collect the data for family-owned property. Given each person's family members, and the estate(房产)info under his/her own name, we need to know the size of each f...原创 2018-12-07 20:33:56 · 208 阅读 · 0 评论 -
关于结构体花式排序
对于结构体成员数据类型纷繁多样的,可以直接用map把属性存下来,比如用name,id什么的来映射,然后筛选出要排序的数据,push进一个vector里,再排序输出。...原创 2018-12-02 00:49:22 · 204 阅读 · 0 评论 -
Subway Map(图的遍历,麻烦
用 vector 类型的line[a[i-1]*10000+a[i]] 像这样子存 是否换乘开vector的点来存边In the big cities, the subway systems always look so complex to the visitors. To give you some sense, the following figure shows the map of ...原创 2018-12-04 16:46:24 · 1079 阅读 · 0 评论 -
Infix Expression(树遍历
从根节点DFS,当前节点不是根节点,往左/右子树遍历时输出( 号,回溯时输出 )号Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with parentheses reflecting the precedences of the operators.Inp...原创 2018-12-04 16:38:15 · 588 阅读 · 0 评论 -
Rational Arithmetic(模拟分数的加减乘除
For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient.Input Specification:Each input file contains one test cas...原创 2018-11-26 22:42:50 · 466 阅读 · 0 评论 -
Travelling Salesman Problem(初始化。。。
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...原创 2018-11-29 11:35:08 · 199 阅读 · 0 评论 -
LCA in a Binary Tree(貌似不是正解
给出中序遍历和先序遍历求俩节点的LCAThe 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 ...原创 2018-11-29 09:56:12 · 207 阅读 · 0 评论 -
To Fill or Not to Fill(贪心
可恶心了,先找出最低的加油站,如果最低的站就是当前站,则看看能不能走到终点,否则加满,然后判断一下能不能走到下一站,能走就走下一站,不能走能走多少是多少。如果最优站不是本站,然后看看不加油能不能走到最优站,如果不能,就找与之中间的次优站,加足以走到次优站的油。。。每走一站就dfs一下。题目描述With highways available, driving a car from Hangzho...原创 2018-11-25 23:32:47 · 138 阅读 · 0 评论 -
Sharing(又是链表
找两个链表的公共后缀的第一个字符的地址对于怎样处理链表类的题目,大概建一个结构体是比较方便的,定好一个表头,然后一直找next找到等于-1就可以了题目描述To store English words, one method is to use linked lists and store aword letter by letter. To save some space, we may...原创 2018-11-25 21:45:45 · 174 阅读 · 0 评论 -
Linked List Sorting 链表
找出一条有效的链表按value排序输出,输入没有环题目描述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...原创 2018-11-25 17:03:47 · 145 阅读 · 0 评论 -
%0Xd补零
%0Xd补零原创 2018-11-24 10:38:29 · 736 阅读 · 0 评论 -
Shopping in Mars
先求出前缀和,枚举左端点,值得注意的是要定义前缀和第一项是0题目描述Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment...原创 2018-11-24 00:32:08 · 186 阅读 · 0 评论 -
Shuffling Machine
判断扑克牌一定要从下标0开始输入,不然处理花色和点数时会遇到13/131以及13%130的尴尬情况题目描述Shuffling is a procedure used to randomize a deck of playing cards.Because standard shuffling techniques are seen as weak, and in order toavoid...原创 2018-11-23 23:31:44 · 121 阅读 · 0 评论 -
Pop Sequence(用stack就是无脑模拟
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 t...原创 2018-11-25 16:08:26 · 168 阅读 · 0 评论 -
Heaps(判断堆
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...原创 2018-11-29 21:34:24 · 400 阅读 · 0 评论 -
Scientific Notation (将科学计数法转成数字
#include&lt;bits/stdc++.h&gt;#include &lt;iostream&gt;#include &lt;map&gt;#include &lt;string&gt;#include&lt;vector&gt;#include&lt;stack&gt;using namespac原创 2018-11-26 22:11:51 · 815 阅读 · 0 评论 -
字符串小剧场
substr(pos,len)从pos位置截取长度为len的字符串find(“X”)寻找字母X的位置atoi(a)将string转化为intc_str(a)提取出a的string部分,不包含符号insert(pos,S,n)在pos处插入S的前n个字符erase(A,B)去掉A~Bstrcmp(a,b)比较a,b是否一样strcpy(a,b)把b复制到a...原创 2018-11-26 21:13:46 · 140 阅读 · 0 评论 -
Recommendation System(set
知道有Set这种数据结构就会做了Recommendation system predicts the preference that a user would give to an item. Now you are asked to program a very simple recommendation system that rates the user’s preference by t...原创 2018-12-04 16:24:33 · 238 阅读 · 0 评论 -
ZigZagging on a Tree(由中序遍历和后序遍历求前序遍历
基本上就是由中序遍历和后序遍历求前序遍历将前序遍历按层数存,输出的时候根据层数的奇偶按顺序/逆序输出就可以了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 a...原创 2018-12-04 16:22:10 · 849 阅读 · 0 评论 -
Eulerian Path
**通路:**在无向图中由点边交替组成的序列就是通路(如果这个图是简单的,那么也可以使用点的序列来表示),如果首尾的点相同,则称为一条回路**无向图的连通性:**无向图中任意一对点之间均有通路**欧拉通路:**从某个顶点出发,将所有的边遍历一遍并且仅经过一遍的通路序列称为欧拉通路,连通的多重图有欧拉回路而无欧拉回路当且仅当它恰有两个奇数度顶点这里说明了欧拉通路的条件:图是连通的,没有孤立...原创 2018-12-04 16:16:46 · 382 阅读 · 0 评论 -
Chain the Ropes(找规律/贪心
用DFS找规律。。。然后发现从小打到大连起来就是最优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...原创 2018-12-04 16:11:07 · 273 阅读 · 0 评论 -
Hashing - Average Search Time(哈希二次探测再散列
知道如下两个公式:Hash=key%sizeid=(Hash(x)+C)%sizeC = 1*1 , -1*1 , 2*2 , -2*2…size*size , -size*sizeid就是要将X插入到哈希表里的下标值第一行是已经插入的一个序列第二行是要插入的序列,判断会不会冲突The task of this problem is simple: insert a sequenc...原创 2018-11-29 21:41:10 · 765 阅读 · 0 评论 -
Topological Order (判断是不是拓扑排序
所谓拓扑排序就是删除入度为0的点的顺序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 wri...原创 2018-11-29 21:36:24 · 1202 阅读 · 0 评论