自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

无敌兔0x01

无欲速,无见小利。欲速,则不达;见小利,则大事不成。

  • 博客(141)
  • 资源 (2)
  • 问答 (5)
  • 收藏
  • 关注

原创 【图论】B038_LG_课程安排 IV(dfs / Floyd)

一、ProblemThere are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have direct prerequisites, for example, to take course 0 you have first to take course 1, which is expressed as a pair: [1,0]Given the total number of cours

2020-05-31 22:15:12 305

原创 【图论】B037_LG_重新规划路线(dfs + 正反存图)

一、ProblemThere are n cities numbered from 0 to n-1 and n-1 roads such that there is only one way to travel between two different cities (this network form a tree). Last year, The ministry of transport decided to orient the roads in one direction because t

2020-05-31 21:30:04 298

原创 【数组】C074_LC_数组中两元素的最大乘积(暴力 / 最大与次大)

一、ProblemGiven the array of integers nums, you will choose two different indices i and j of that array. Return the maximum value of (nums[i]-1)*(nums[j]-1).Input: nums = [3,4,5,2]Output: 12 Explanation: If you choose the indices i=1 and j=2 (indexed fr

2020-05-31 20:43:37 236

原创 【贪心】B037_LC_切割后面积最大的蛋糕(排序)

一、ProblemGiven a rectangular cake with height h and width w, and two arrays of integers horizontalCuts and verticalCuts where horizontalCuts[i] is the distance from the top of the rectangular cake to the ith horizontal cut and similarly, verticalCuts[j] i

2020-05-31 12:01:55 298

原创 【字符串】B048_LC_检查一个字符串是否包含所有长度为 K 的二进制子串(暴力 / 优化 / 回溯)

一、ProblemGiven a binary string s and an integer k.Return True if any binary code of length k is a substring of s. Otherwise, return False.Input: s = "00110110", k = 2Output: trueExplanation: The binary codes of length 2 are "00", "01", "10" and "11".

2020-05-31 08:16:19 431

原创 【栈】A012_LC_柱状图中最大的矩形(暴力 / 单调栈)

一、ProblemGiven n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Example:Input: [2,1,5,6,2,3]Output: 10二、Solution方法一:暴力(超时)对于位置 iii,要想和位置 iii 的柱形拼

2020-05-30 22:17:54 234

原创 【图论】C036_LG_最大食物链计数(拓扑排序 + dp)

一、Problem你知道食物链吗?Delia 生物考试的时候,数食物链条数的题目全都错了,因为她总是重复数了几条或漏掉了几条。于是她来就来求助你,然而你也不会啊!写一个程序来帮帮她吧。题目描述给你一个食物网,你要求出这个食物网中最大食物链的数量。(这里的“最大食物链”,指的是生物学意义上的食物链,即最左端是不会捕食其他生物的生产者,最右端是不会被其他生物捕食的消费者。)Delia 非常急,所以你只有 1 秒的时间。由于这个结果可能过大,你只需要输出总数模上 80112002 的结果。输入格式

2020-05-29 22:59:29 537

原创 【图论】C035_LG_炸铁路(dfs 枚举桥 / 并查集)

一、ProblemA 国派出将军uim,对 B 国进行战略性措施,以解救涂炭的生灵。B 国有 nn 个城市,这些城市以铁路相连。任意两个城市都可以通过铁路直接或者间接到达。uim 发现有些铁路被毁坏之后,某两个城市无法互相通过铁路到达。这样的铁路就被称为 key road。uim 为了尽快使该国的物流系统瘫痪,希望炸毁铁路,以达到存在某两个城市无法互相通过铁路到达的效果。然而,只有一发炮弹(A 国国会不给钱了)。所以,他能轰炸哪一条铁路呢?6 61 22 32 43 54 55 6

2020-05-29 21:40:03 320

原创 【回溯】B063_LG_数的划分(记录 pre / 剪枝)

一、Problem7 34说明/提示四种分法为:1,1,51,2,41,3,32,2,3二、Solution方法一:dfs最暴力的做法就是,用一个容器实时记录取到的数,当 n = N && k = K 时,再用 set 去重WA:set 中原本的 equals 方法根本对数组取不了重。import java.util.*;import java.math.*;import java.io.*;public class Main{ static clas

2020-05-28 22:41:35 264 2

原创 【回溯】B062_LG_矩阵取数(选与不选)

一、Problem34 467 75 63 1029 29 92 1421 68 71 568 67 91 252 387 70 8510 3 173 31 1 11 99 11 1 127117299二、Solution方法一:dfs和棋子放置很像,先从左往右搜,到达最右边就换一行,继续从左向右搜。对于每一个格子的数,我们都可以选货不选。选完最后一行,就结算。import java.util.*;import java.math.*;import

2020-05-28 21:32:41 183

原创 【回溯】C061_LG_美食配料(选与不选)

一、Problem输出格式输出酸度和甜度的最小的绝对差。输入输出样例41 72 63 84 91二、Solution方法一:dfs对于每一种配料 iii,我们都可以选择添加或不添加:添加就是:dfs(x+1, p*a[x], q+b[x])不添加就是:dfs(x+1, p, q)注:初始值为 p = 1,q = 0,但题目说至少需要一种配料,所以,需要特判,提前返回。import java.util.*;import java.math.*;import

2020-05-28 20:25:52 154

原创 【搜索】B059_LG_字串变换(bfs)

一、Problem输出格式若在 10 步(包含 10 步)以内能将 A 变换为 B,则输出最少的变换步数;否则输出 NO ANSWER!输入abcd xyzabc xuud yy yz输出3二、Solution方法一:bfsimport java.util.*;import java.math.*;import java.io.*;public class Main { static class Solution { String a, b, fr[], to[]

2020-05-28 17:58:00 201

原创 【数组】B073_LC_和可被 K 整除的子数组(前缀和 / 递推)

一、ProblemGiven an array A of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by K.Input: A = [4,5,0,-2,-3,1], K = 5Output: 7Explanation: There are 7 subarrays with a sum divisible by K = 5:[4, 5, 0, -2, -3, 1

2020-05-28 08:54:41 188

原创 【搜索】B058_LG_玉米迷宫(bfs 传送门)

一、Problem去年秋天,奶牛们去参观了一个玉米迷宫,迷宫里有一些传送装置,可以将奶牛从一点到另一点进行瞬间转移。这些装置可以双向使用:一头奶牛可以从这个装置的起点立即到此装置的终点,同时也可以从终点出发,到达这个装置的起点。如果一头奶牛处在这个装置的起点或者终点,这头奶牛就必须使用这个装置。玉米迷宫的外部完全被玉米田包围,除了唯一的一个出口。这个迷宫可以表示为 N×M 的矩阵 (2 ≤ N ≤ 300; 2 ≤ M ≤ 300),矩阵中的每个元素都由以下项目中的一项组成:#:玉米,这些格子是不可

2020-05-27 21:53:56 536

原创 【搜索】C057_LG_填涂颜色(Flood Fill + 扩展边界)

一、Problem由数字 0 组成的方阵中,有一任意形状闭合圈,闭合圈由数字 1 构成,围圈时只走上下左右 4 个方向。现要求把闭合圈内的所有空间都填写成 2.例如:6×6 的方阵(n=6)输入格式每组测试数据第一行一个整数 n(1≤n≤30)接下来 n 行,由 0 和 1 组成的 n×n 的方阵。方阵内只有一个闭合圈,圈内至少有一个 0。输出格式已经填好数字 2 的完整方阵。60 0 0 0 0 00 0 1 1 1 10 1 1 0 0 11 1 0 0 0 11 0 0 0

2020-05-27 19:44:02 271

原创 【数组】B072_LC_寻找重复数(二分思想)

一、ProblemGiven an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.Input: [1,3,4,2,2]Outpu

2020-05-27 08:20:13 157

原创 【线性 dp】B003_LC_最长湍流子数组(读题 dp / 双指针)

一、ProblemA subarray A[i], A[i+1], …, A[j] of A is said to be turbulent if and only if:For i <= k < j, A[k] > A[k+1] when k is odd, and A[k] < A[k+1] when k is even;OR, for i <= k < j, A[k] > A[k+1] when k is even, and A[k] < A[k

2020-05-26 20:51:48 276

原创 【线性 dp】B015_LC_爱生气的书店老板(注意分钟数 X)

一、ProblemToday, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.On some minutes, the bookstore owner is

2020-05-26 17:58:31 211

原创 【设计】B001_用队列实现栈(双端队列 + Map / Map + 自定义双向链表 (代办))

一、ProblemDesign and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key)Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.

2020-05-25 22:40:24 246

原创 【数组】A070_LC_寻找两个正序数组的中位数(暴力 / 双指针 / 二分(代办))

一、ProblemThere are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).You may assume nums1 and nums2 cannot be both empty.nums1 = [1, 3]nums2

2020-05-25 08:03:25 268

原创 【区间 dp】A012_LC_两个子序列的最大点积(分类讨论)

一、ProblemGiven two arrays nums1 and nums2.Return the maximum dot product between non-empty subsequences of nums1 and nums2 with the same length.A subsequence of a array is a new array which is formed from the original array by deleting some (can be none

2020-05-24 22:44:07 217

原创 【树】B032_LC_ 二叉树中的伪回文路径(暴力 / 优化)

一、ProblemGiven a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be pseudo-palindromic if at least one permutation of thInput: root = [2,3,1,3,1,null,1]Output: 2 Explanation: The figure above represents the g

2020-05-24 21:40:11 261

原创 【字符串】B047_LC_定长子串中元音的最大数目(滑动窗口)

一、ProblemGiven a string s and an integer k.Return the maximum number of vowel letters in any substring of s with length k.Vowel letters in English are (a, e, i, o, u).Input: s = "abciiidef", k = 3Output: 3Explanation: The substring "iii" contains 3 vo

2020-05-24 21:14:28 257

原创 【字符串】B049_LC_字符串的排列(滑窗)

一、ProblemGiven two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string’s permutations is the substring of the second string.Input: s1 = "ab" s2 = "eidbaooo"Output: TrueExplana

2020-05-24 20:12:23 222

原创 【字符串】B048_LC_至少有K个重复字符的最长子串(滑窗 + 分治 / 优化)

一、ProblemFind the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times.Input:s = "aaabb", k = 3Output:3The longest substring is "aaa", as 'a' is repeate

2020-05-24 16:39:42 233

原创 【字符串】B047_LC_找到字符串中所有字母异位词(滑动窗口)

一、ProblemGiven a string s and a non-empty string p, find all the start indices of p’s anagrams in s.Strings consists of lowercase English letters only and the length of both strings s and p will not be larger than 20,100.The order of output does not mat

2020-05-24 09:55:42 233

原创 【字符串】A046_LC_最小覆盖子串(滑动窗口)

一、ProblemGiven a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).Input: S = "ADOBECODEBANC", T = "ABC"Output: "BANC"Note:If there is no such window in S that covers all characters i

2020-05-23 22:53:48 1236

原创 【区间 dp】A011_LC_恢复数组(剪枝)

一、ProblemA program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits and all we know is that all integers in the array were in the range [1, k] and there are no leading zeros

2020-05-22 23:22:21 181

原创 【区间 dp】B010_LC_最长回文子串(暴力 / dp / 中心扩展(代办))

一、Problem二、Solution方法一:暴力不用先取子串,可以利用 s 的字符串数组根据索引进行全局比较取子串的话会超时的。class Solution { char[] cs; public String longestPalindrome(String s) { if (s.length() == 1) return s; String res = ""; cs = s.toCharArray

2020-05-21 21:36:17 200

原创 【思维题】C009_LC_上升下降字符串(双向扫描)

一、ProblemGiven a string s. You should re-order the string using the following algorithm:Pick the smallest character from s and append it to the result.Pick the smallest character from s which is greater than the last appended character to the result an

2020-05-20 22:47:30 549

原创 【字符串】B044_LC_每个元音包含偶数次的最长子字符串(状态压缩)

一、ProblemGiven the string s, return the size of the longest substring containing each vowel an even number of times. That is, ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’ must appear an even number of times.Input: s = "eleetminicoworoep"Output: 13Explanation: The longe

2020-05-20 22:19:26 534

原创 【树】B031_LC_ 二叉树中的最长交错路径(递归 / 树形 dp)

一、ProblemGiven a binary tree root, a ZigZag path for a binary tree is defined as follow:Choose any node in the binary tree and a direction (right or left).If the current direction is right then move to the right child of the current node otherwise move

2020-05-20 17:52:00 245

原创 【字符串】B043_LC_包含所有三种字符的子字符串数目(双指针)

一、ProblemGiven a string s consisting only of characters a, b and c.Return the number of substrings containing at least one occurrence of all these characters a, b and c.Input: s = "abcabc"Output: 10Explanation: The substrings containing at least one o

2020-05-20 16:24:32 241

原创 【数学】C074_LC_时钟指针的夹角(补角)

一、ProblemGiven two numbers, hour and minutes. Return the smaller angle (in degrees) formed between the hour and the minute hand.二、Solution方法一:求补角class Solution { public double angleClock(int h, int m) { double h2a = 360/12, m2a = h2a/60;

2020-05-19 22:16:42 275

原创 【搜索】A056_LC_跳跃游戏 IV(一维 bfs / 双向 bfs)

一、ProblemGiven an array of integers arr, you are initially positioned at the first index of the array.In one step you can jump from index i to index:i + 1 where: i + 1 < arr.length.i - 1 where: i - 1 >= 0.j where: arr[i] == arr[j] and i != j.

2020-05-19 21:41:51 198

原创 【线性 dp】A002_LC_跳跃游戏 V(记忆化搜索 / 排序 + dp + 疑惑)

一、ProblemGiven an array of integers arr and an integer d. In one step you can jump from index i to index:i + x where: i + x < arr.length and 0 < x <= d.i - x where: i - x >= 0 and 0 < x <= d.In addition, you can only jump from index i

2020-05-19 20:07:16 247

原创 【数组】C069_LC_数组序号转换(map / 桶排序 + 前缀和)

一、ProblemGiven an array of integers arr, replace each element with its rank.The rank represents how large the element is. The rank has the following rules:Rank is an integer starting from 1.The larger the element, the larger the rank. If two elements

2020-05-19 11:31:18 273

原创 【思维题】B008_LC_破坏回文串(字符计数)

一、ProblemGiven a palindromic string palindrome, replace exactly one character by any lowercase English letter so that the string becomes the lexicographically smallest possible string that isn’t a palindrome.After doing so, return the final string. If t

2020-05-19 10:38:28 187

原创 【数组】B068_LC_将矩阵按对角线排序(冒泡思想 / 规律)

一、ProblemGiven a m * n matrix mat of integers, sort it diagonally in ascending order from the top-left to the bottom-right then return the sorted array.Input: mat = [[3,3,1,1],[2,2,1,2],[1,1,1,2]]Output: [[1,1,1,1],[1,2,2,2],[1,2,3,3]] Constraints:m

2020-05-18 23:12:38 305

原创 【数学】C073_JM_好运2020(质因数分解)

一、Problem二、Solution方法一:暴力做法将一个数的所有因子都求出来,并判断这些因子是否是质数,佛乐…注:求所有质因数和求因数再求质数时不一样的。import java.util.*;import java.math.*;import java.io.*;public class Main{ static class Solution { boolean isPrime(int n) { for (int i = 2; i <= n/i; i++) {

2020-05-18 17:11:19 378

初一数学知识点汇总图.7z

参与《原力计划【第二季】— 打卡挑战》的文章入选【打卡挑战周榜】的博主,即可获得此勋章。参与《原力计划【第二季】— 打卡挑战》的文章入选【打卡挑战周榜】的博主,即可获得此勋章。参与《原力计划【第二季】— 打卡挑战》的文章入选【打卡挑战周榜】的博主,即可获得此勋章。

2020-05-20

icpc2019.pdf

icpc 基础,推荐一下!

2020-04-03

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除