- 博客(150)
- 收藏
- 关注
原创 [UVA] Non-boring sequences
题目:https://vjudge.net/problem/UVA-1608#include<iostream>#include<cstdio>#include<cstring>#include<map>#include<vector>#include<algorithm>#include<string...
2020-03-08 21:06:18
226
原创 [UVA] Amphiphilic Carbon Molecules
题目:https://vjudge.net/problem/UVA-1606#include<iostream>#include<cstdio>#include<cstring>#include<map>#include<vector>#include<algorithm>#include<string...
2020-02-27 20:18:17
248
1
原创 [UVA] Lattice Animals
题目:https://vjudge.net/problem/UVA-1602刘汝佳的代码:#include<iostream>#include<cstdio>#include<cstring>#include<map>#include<vector>#include<algorithm>#include&...
2020-02-20 19:49:04
156
原创 [LeetCode] 二叉搜索树迭代器
实现一个二叉搜索树迭代器。你将使用二叉搜索树的根节点初始化迭代器。调用 next() 将返回二叉搜索树中的下一个最小的数。示例:BSTIterator iterator = new BSTIterator(root);iterator.next(); // 返回 3iterator.next(); // 返回 7iterator.hasNext(); // 返回...
2020-02-19 22:59:59
130
原创 [UVA] Power Calculus
题目:https://vjudge.net/problem/UVA-1374#include<iostream>#include<cstdio>#include<cstring>#include<map>#include<vector>#include<algorithm>#include<string...
2020-02-19 18:32:44
149
原创 [UVA] The Rotation Game
题目:https://vjudge.net/problem/UVA-1343#include<iostream>#include<cstdio>#include<cstring>#include<map>#include<vector>#include<algorithm>#include<string...
2020-02-19 15:52:08
139
转载 埃及分数
埃及分数问题在古埃及,人们使用单位分数的和(即1/a,a是自然数)来表示一切有理数,例如,2/3=1/2+1/6,但是不允许2/3=1/3+1/3,因为在加数中不允许有相同的。对于一个分数a/b,表示的方法有很多种,其中加数少的比加数多的好,如果加数个数相同,那么最小的分数越大越好。例如,19/45=1/5+1/6+1/18是最优方案。输入两个整数a,b(0<a<b<500...
2020-02-18 20:04:01
1522
转载 [UVA] The Morning after Halloween
题目:https://vjudge.net/problem/UVA-1601#include<iostream>#include<cstdio>#include<cstring>#include<map>#include<vector>#include<algorithm>#include<string...
2020-02-16 00:14:29
115
原创 [UVA] Fill
题目:https://vjudge.net/problem/UVA-10603#include<iostream>#include<cstdio>#include<cstring>#include<map>#include<vector>#include<algorithm>#include<strin...
2020-02-15 19:28:37
102
原创 [UVA] Mobile Computing
题目:https://vjudge.net/problem/UVA-1354#include<iostream>#include<cstdio>#include<cstring>#include<map>#include<vector>#include<algorithm>#include<string...
2020-02-14 20:39:22
118
原创 [UVA] Undraw the Trees
题目:https://vjudge.net/problem/UVA-10562#include<iostream>#include<cstdio>#include<cstring>#pragma warning(disable:4996)using namespace std;const int maxn = 200 + 5;char bu...
2020-02-09 18:33:48
190
1
原创 [UVA] Abbott's Revenge
题目:https://vjudge.net/problem/UVA-816#include<iostream>#include<vector>#include<string>#include <sstream>#include<queue>#pragma warning(disable:4996)using names...
2020-02-08 18:38:16
142
原创 [UVA] Quadtrees
题目:https://vjudge.net/problem/UVA-297#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int len = 32;const int maxn = 1024 + 5;char s[maxn];int bu...
2020-02-07 17:02:36
110
原创 [UVA] The Falling Leaves
题目:https://vjudge.net/problem/UVA-699#include<iostream>#include<vector>#include<cstring>using namespace std;const int maxn = 200;int sum[maxn];void build(int pos){ int v...
2020-02-07 16:04:57
144
原创 [UVA] Tree
题目:https://vjudge.net/problem/UVA-548#include<iostream>#include<string>#include<sstream>#include<algorithm>using namespace std;const int manx = 10000 + 5;int in_order...
2020-02-07 12:43:34
128
转载 [UVA] Trees on the level
题目:https://vjudge.net/problem/UVA-122#include<cstdio>#include<cstring>#include<vector>#include<queue>#pragma warning(disable:4996)using namespace std;const int maxn =...
2020-02-07 00:14:42
120
原创 [LeetCode] 二叉树中的最大路径和
给定一个非空二叉树,返回其最大路径和。本题中,路径被定义为一条从树中任意节点出发,达到任意节点的序列。该路径至少包含一个节点,且不一定经过根节点。示例 1:输入: [1,2,3] 1 / \ 2 3输出: 6示例2:输入: [-10,9,20,null,null,15,7] -10/ \9 20/ ...
2020-02-03 17:22:55
214
原创 [LeetCode] 扁平化多级双向链表
您将获得一个双向链表,除了下一个和前一个指针之外,它还有一个子指针,可能指向单独的双向链表。这些子列表可能有一个或多个自己的子项,依此类推,生成多级数据结构,如下面的示例所示。扁平化列表,使所有结点出现在单级双链表中。您将获得列表第一级的头部。示例:输入:1---2---3---4---5---6--NULL | 7---8---9---1...
2020-02-02 15:08:56
178
转载 [转]大整数类BigInteger
算法竞赛入门经典(第2版) 第5章C++与STL入门大整数类BigInteger跟踪调试后的感悟。1、=(long long num)该赋值方式实际运用价值不大,输入数据一长容易越界。=(const string& str)赋值方式极具实用价值,只要string不越界,就可以处理该整数。2、将大整数分块处理,BASE=100000000,WIDTH=8,每八位数为一个单元,...
2020-02-01 16:06:46
246
原创 [UVa 1592] Database
#include<iostream>#include<map>#include<cstdio>#include<string>#include<vector>using namespace std;const int maxr = 10000 + 5;const int maxc = 15;typedef pair<...
2020-01-31 15:03:57
102
原创 [LeetCode] 路径总和 II
给定一个二叉树和一个目标和,找到所有从根节点到叶子节点路径总和等于给定目标和的路径。说明:叶子节点是指没有子节点的节点。示例:给定如下二叉树,以及目标和sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ ...
2020-01-29 12:55:55
122
原创 [LeetCode] 二叉树最大宽度
给定一个二叉树,编写一个函数来获取这个树的最大宽度。树的宽度是所有层中的最大宽度。这个二叉树与满二叉树(full binary tree)结构相同,但一些节点为空。每一层的宽度被定义为两个端点(该层最左和最右的非空节点,两端点间的null节点也计入长度)之间的长度。示例 1:输入: 1 / \ 3 2 ...
2020-01-28 19:59:46
737
原创 [LeetCode] 钥匙和房间
有 N 个房间,开始时你位于 0 号房间。每个房间有不同的号码:0,1,2,...,N-1,并且房间里可能有一些钥匙能使你进入下一个房间。在形式上,对于每个房间 i 都有一个钥匙列表 rooms[i],每个钥匙 rooms[i][j] 由 [0,1,...,N-1] 中的一个整数表示,其中 N = rooms.length。 钥匙 rooms[i][j] = v 可以打开编号为 v 的房间。...
2020-01-27 15:48:54
212
原创 [LeetCode] 二叉树的最小深度
给定一个二叉树,找出其最小深度。最小深度是从根节点到最近叶子节点的最短路径上的节点数量。说明:叶子节点是指没有子节点的节点。示例:给定二叉树[3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回它的最小深度 2.BFS:class Solution {public: int ...
2020-01-27 14:24:49
188
原创 [LeetCode] 二叉树层次遍历
1. 给定一个二叉树,返回其按层次遍历的节点值。 (即逐层地,从左到右访问所有节点)。例如:给定二叉树:[3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回其层次遍历结果:[ [3], [9,20], [15,7]]/** * Definition for a binary tre...
2020-01-27 13:26:51
176
原创 [LeetCode] 恢复二叉搜索树
二叉搜索树中的两个节点被错误地交换。请在不改变其结构的情况下,恢复这棵树。示例1:输入: [1,3,null,null,2] 1/3\ 2输出: [3,1,null,null,2] 3/1\ 2示例2:输入: [3,1,4,null,null,2] 3/ \1 4 /2输出: [2...
2020-01-25 14:21:40
122
原创 [LeetCode] 不同的二叉搜索树 II
给定一个整数 n,生成所有由 1 ...n 为节点所组成的二叉搜索树。示例:输入: 3输出:[[1,null,3,2],[3,2,null,1],[3,1,null,null,2],[2,1,3],[1,null,2,null,3]]解释:以上的输出对应以下 5 种不同结构的二叉搜索树: 1 3 3 2 ...
2020-01-24 20:02:52
77
原创 [LeetCode] 颜色分类
给定一个包含红色、白色和蓝色,一共n 个元素的数组,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。此题中,我们使用整数 0、1 和 2 分别表示红色、白色和蓝色。注意:不能使用代码库中的排序函数来解决这道题。示例:输入: [2,0,2,1,1,0]输出: [0,0,1,1,2,2]进阶:一个直观的解决方案是使用计数排序的两趟扫描算法。首...
2020-01-15 16:31:30
167
原创 [LeetCode] Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row ...
2020-01-15 15:24:32
89
原创 [LeetCode] 旋转链表
Given a linkedlist, rotate the list to the right by k places, where k is non-negative.Example 1:Input: 1->2->3->4->5->NULL, k = 2Output: 4->5->1->2->3->NULLExplana...
2020-01-12 19:41:12
79
原创 [LeetCode] 不同路径II
一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” )。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为“Finish”)。现在考虑网格中有障碍物。那么从左上角到右下角将会有多少条不同的路径?网格中的障碍物和空位置分别用 1 和 0 来表示。说明:m和 n 的值均不超过 100。示例1:输入:[[0,...
2020-01-11 11:42:18
145
原创 [LeetCode] 最小路径和
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at a...
2020-01-11 11:21:58
98
原创 [LeetCode] 使用最小花费爬楼梯
数组的每个索引做为一个阶梯,第i个阶梯对应着一个非负数的体力花费值cost[i](索引从0开始)。每当你爬上一个阶梯你都要花费对应的体力花费值,然后你可以选择继续爬一个阶梯或者爬两个阶梯。您需要找到达到楼层顶部的最低花费。在开始时,你可以选择从索引为 0 或 1 的元素作为初始阶梯。示例1:输入: cost = [10, 15, 20]输出: 15解释: 最低花费是从co...
2020-01-10 20:01:19
101
转载 【转】堆和栈的区别
堆和栈的区别(博客园):http://www.cnblogs.com/jiahuafu/p/8575044.html关于堆栈的讲解(我见过的最经典的):https://blog.youkuaiyun.com/yingms/article/details/53188974堆栈的工作原理:https://blog.youkuaiyun.com/laoqiuge/article/details/53728179...
2020-01-09 12:28:16
63
原创 [LeetCode] 第K个排列
The set [1,2,3,...,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order, we get the following sequence for n = 3:"123""132""213""231""312""32...
2020-01-08 18:44:36
91
原创 [LeetCode] 重复叠加字符串匹配
给定两个字符串 A 和 B, 寻找重复叠加字符串A的最小次数,使得字符串B成为叠加后的字符串A的子串,如果不存在则返回 -1。举个例子,A = "abcd",B = "cdabcdab"。答案为 3,因为 A 重复叠加三遍后为“abcdabcdabcd”,此时 B 是其子串;A 重复叠加两遍后为"abcdabcd",B 并不是其子串。注意:A与B字符串的长度在1和100...
2020-01-06 23:49:42
187
原创 [LeetCode] Longest Duplicate Substring
Given a string S, consider all duplicated substrings: (contiguous) substrings of S that occur 2 or more times.(The occurrencesmay overlap.)Return any duplicatedsubstring that has the longest pos...
2020-01-06 20:22:34
375
原创 [LeetCode] 子串的最大出现次数
给你一个字符串s ,请你返回满足以下条件且出现次数最大的任意子串的出现次数:子串中不同字母的数目必须小于等于 maxLetters 。子串的长度必须大于等于minSize 且小于等于maxSize 。示例 1:输入:s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4输出:2解释:子串 "aab" 在原字...
2020-01-05 00:02:12
478
原创 [LeetCode] 最后一个单词的长度
给定一个仅包含大小写字母和空格' '的字符串,返回其最后一个单词的长度。如果不存在最后一个单词,请返回 0。说明:一个单词是指由字母组成,但不包含任何空格的字符串。示例:输入: "Hello World"输出: 5class Solution {public: int lengthOfLastWord(string s) { int r...
2020-01-04 23:19:44
79
原创 [LeetCode] 螺旋矩阵
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.Example 1:Input:[[ 1, 2, 3 ],[ 4, 5, 6 ],[ 7, 8, 9 ]]Output: [1,2,3,6,9,8,7,4,5]Ex...
2020-01-03 14:15:58
93
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人