![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
Lei_lz
西南大学在读
展开
-
[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 · 172 阅读 · 0 评论 -
[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 · 176 阅读 · 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 · 118 阅读 · 0 评论 -
[LeetCode] 二叉搜索树迭代器
实现一个二叉搜索树迭代器。你将使用二叉搜索树的根节点初始化迭代器。调用 next() 将返回二叉搜索树中的下一个最小的数。示例:BSTIterator iterator = new BSTIterator(root);iterator.next(); // 返回 3iterator.next(); // 返回 7iterator.hasNext(); // 返回...原创 2020-02-19 22:59:59 · 102 阅读 · 0 评论 -
[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 · 99 阅读 · 0 评论 -
[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 · 99 阅读 · 0 评论 -
埃及分数
埃及分数问题在古埃及,人们使用单位分数的和(即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 · 1371 阅读 · 0 评论 -
[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 · 87 阅读 · 0 评论 -
[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 · 73 阅读 · 0 评论 -
[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 · 85 阅读 · 0 评论 -
[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 · 134 阅读 · 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 · 98 阅读 · 0 评论 -
[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 · 85 阅读 · 0 评论 -
[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 · 110 阅读 · 0 评论 -
[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 · 104 阅读 · 0 评论 -
[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 · 92 阅读 · 0 评论 -
[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 · 160 阅读 · 0 评论 -
[LeetCode] 扁平化多级双向链表
您将获得一个双向链表,除了下一个和前一个指针之外,它还有一个子指针,可能指向单独的双向链表。这些子列表可能有一个或多个自己的子项,依此类推,生成多级数据结构,如下面的示例所示。扁平化列表,使所有结点出现在单级双链表中。您将获得列表第一级的头部。示例:输入:1---2---3---4---5---6--NULL | 7---8---9---1...原创 2020-02-02 15:08:56 · 137 阅读 · 0 评论 -
[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 · 75 阅读 · 0 评论 -
[LeetCode] 路径总和 II
给定一个二叉树和一个目标和,找到所有从根节点到叶子节点路径总和等于给定目标和的路径。说明:叶子节点是指没有子节点的节点。示例:给定如下二叉树,以及目标和sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ ...原创 2020-01-29 12:55:55 · 88 阅读 · 0 评论 -
[LeetCode] 二叉树最大宽度
给定一个二叉树,编写一个函数来获取这个树的最大宽度。树的宽度是所有层中的最大宽度。这个二叉树与满二叉树(full binary tree)结构相同,但一些节点为空。每一层的宽度被定义为两个端点(该层最左和最右的非空节点,两端点间的null节点也计入长度)之间的长度。示例 1:输入: 1 / \ 3 2 ...原创 2020-01-28 19:59:46 · 700 阅读 · 0 评论 -
[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 · 155 阅读 · 0 评论 -
[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 · 165 阅读 · 0 评论 -
[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 · 128 阅读 · 0 评论 -
[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 · 84 阅读 · 0 评论 -
[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 · 58 阅读 · 0 评论 -
[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 · 66 阅读 · 0 评论 -
[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 · 60 阅读 · 0 评论 -
[LeetCode] 不同路径II
一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” )。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为“Finish”)。现在考虑网格中有障碍物。那么从左上角到右下角将会有多少条不同的路径?网格中的障碍物和空位置分别用 1 和 0 来表示。说明:m和 n 的值均不超过 100。示例1:输入:[[0,...原创 2020-01-11 11:42:18 · 107 阅读 · 0 评论 -
[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 · 79 阅读 · 0 评论 -
[LeetCode] 使用最小花费爬楼梯
数组的每个索引做为一个阶梯,第i个阶梯对应着一个非负数的体力花费值cost[i](索引从0开始)。每当你爬上一个阶梯你都要花费对应的体力花费值,然后你可以选择继续爬一个阶梯或者爬两个阶梯。您需要找到达到楼层顶部的最低花费。在开始时,你可以选择从索引为 0 或 1 的元素作为初始阶梯。示例1:输入: cost = [10, 15, 20]输出: 15解释: 最低花费是从co...原创 2020-01-10 20:01:19 · 74 阅读 · 0 评论 -
[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 · 64 阅读 · 0 评论 -
[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 · 152 阅读 · 0 评论 -
[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 · 312 阅读 · 0 评论 -
[LeetCode] 子串的最大出现次数
给你一个字符串s ,请你返回满足以下条件且出现次数最大的任意子串的出现次数:子串中不同字母的数目必须小于等于 maxLetters 。子串的长度必须大于等于minSize 且小于等于maxSize 。示例 1:输入:s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4输出:2解释:子串 "aab" 在原字...原创 2020-01-05 00:02:12 · 418 阅读 · 0 评论 -
[LeetCode] 最后一个单词的长度
给定一个仅包含大小写字母和空格' '的字符串,返回其最后一个单词的长度。如果不存在最后一个单词,请返回 0。说明:一个单词是指由字母组成,但不包含任何空格的字符串。示例:输入: "Hello World"输出: 5class Solution {public: int lengthOfLastWord(string s) { int r...原创 2020-01-04 23:19:44 · 53 阅读 · 0 评论 -
[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 · 61 阅读 · 0 评论 -
[LeetCode] 旋转矩阵 II
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.Example:Input: 3Output:[[ 1, 2, 3 ],[ 8, 9, 4 ],[ 7, 6, 5 ]]解:完全模拟过程,注意好上下左右四个边界就好...原创 2020-01-03 13:24:24 · 100 阅读 · 0 评论 -
[UVa 489] Hangman Judge
In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game ...原创 2019-12-27 01:21:56 · 149 阅读 · 0 评论 -
[LeetCode] Pow(x, n)
Implement pow(x, n), which calculatesx raised to the power n (xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:Input: 2.00000, -2Outp...原创 2019-12-23 22:23:25 · 53 阅读 · 0 评论