ICode9

精准搜索请尝试: 精确搜索
  • LeetCode/用户分组2022-08-12 01:03:26

    有 n 个人被分成数量未知的组。每个人都被标记为一个从 0 到 n - 1 的唯一ID 。 给定一个整数数组 groupSizes ,其中 groupSizes[i] 是第 i 个人所在的组的大小 例如,如果 groupSizes[1] = 3 ,则第 1 个人必须位于大小为 3 的组中 每个人应该恰好只出现在一个组中,并且每个人必

  • c++中unordered_map按照value排序2022-08-11 12:02:06

    整体思路: 利用sort函数 -- 但是sort只能对列表类(比如vector)的进行排序,key-value不行,所以要搞个vector pair(也就是一对key-value)是stl标准模板类,可以作为item放入vector中 重写sort的compare函数,即可对装有pair对的vector进行排序啦 代码如下: //初始化一个mp unordered_map<strin

  • Codeforces Round #809 (Div. 2)2022-08-10 22:02:12

    VP的。 这场 C 是真的恶心,还好一发过了要不然罚时就更起飞了。 D2 考虑枚举 \([l,r]\),判断能否使得所有 \(\lfloor\frac{a_i}{p_i}\rfloor\) 都在 \([l, r]\) 范围内。 对于每个 \(a_i,\lfloor\frac{a_i}{p_i}\rfloor\) 只有 \(\sqrt{n}\) 种值,所以这个判断可以用一个桶实现。 注

  • LeetCode 39 Combination Sum 回溯2022-08-08 19:04:23

    Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order. The same number may be chosen from can

  • 力扣 题目5- 最长回文子串2022-08-07 17:35:13

    题目 题解 1.暴力解法 从前往后遍历途中对 以i为中心对称遍历 和 i也有对称数的对称遍历 2.动态规划 一个回文子串 意味着将两端去掉依然是回文子串 所以我们使用两层vector 记录从开始位置到结束位置是否是回文字符 当s[j]==s[i]时 就去看res[i + 1][j - 1] 是否也为true 是则re

  • LeetCode 90 Subsets II 回溯2022-08-07 05:00:09

    Given an integer array nums that may contain duplicates, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order. Solution 如何处理相同的子集:先把 \(vector\) \(sort\) 一下,然后在 \(ans\)

  • LeetCode 797 All Paths From Source to Target 回溯2022-08-07 03:30:25

    Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1 and return them in any order. The graph is given as follows: graph[i] is a list of all nodes you can visit from node \(i\) (i.e.,

  • 力扣练习——56 寻找右区间2022-08-06 23:03:13

    1.问题描述 给定一组区间(包含起始点和终点),对于每一个区间 i,检查是否存在一个区间 j,它的起始点大于或等于区间 i 的终点,这可以称为 j 在 i 的“右侧”。 对于任何区间,你需要存储的满足条件的区间 j 的最小索引,这意味着区间 j 有最小的起始点可以使其成为“右侧”区间。如果区间 j

  • 8.42022-08-05 14:32:42

    CF1574E 题意: 给一个 \(n \times m\) 的 \(空/0/1\) 矩阵(初始全空)。 \(k\) 次操作,每次操作会把一个格子样式修改。 求每次修改后填充剩下空格子的方案数,使所有 \(2 \times 2\) 的子矩阵 \(4\) 个元素之和为 \(2\) (也就是有 \(2\) 个 \(1\) 和 \(2\) 个 \(0\))。 \(n,m \leq

  • 188. 买卖股票的最佳时机 IV (交易 k次)2022-08-03 22:34:37

      labuladong 题解思路 难度困难780收藏分享切换为英文接收动态反馈 给定一个整数数组 prices ,它的第 i 个元素 prices[i] 是一支给定的股票在第 i 天的价格。 设计一个算法来计算你所能获取的最大利润。你最多可以完成 k 笔交易。 注意:你不能同时参与多笔交易(你

  • LeetCode 239 Sliding Window Maximum 单调队列 [Hard]2022-08-03 02:31:06

    You are given an array of integers nums, there is a sliding window of size \(k\) which is moving from the very left of the array to the very right. You can only see the \(k\) numbers in the window. Each time the sliding window moves right by one posit

  • #Leetcode 912 Sort an Array 快排 改进2022-08-03 00:35:03

    改进版快排,pivot 不再是左边第一个元素,而是正中间元素(或者随机)。 有一个比较坑的地方就是,在每一趟双指针完成所有交换后,需要判断 pivot 需不需要被交换。 比如 test case 1 2 4 3,第一趟开始时 pivot 是 2, 先动右边的指针 j, 找到第一个比 2 小的数也就是 1。此时 1 不应该和 2

  • LeetCode 454 4Sum II2022-08-02 03:31:07

    Given four integer arrays nums1, nums2, nums3, and nums4 all of length n, return the number of tuples (i, j, k, l) such that: \(0 \le i, j, k, l < n\) nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0 Solution 改写一下得到: \[nums1[i]+nums2[j]=-(nums3[k]+

  • Codeforces Round #811 (Div. 3)2022-08-02 02:00:39

    咕咕咕。 D. Color with Occurrences 题意 给定文本串\(t\),和\(n\)个模式串\(s_i\)。 初始时\(t\)的每个字符都是黑色的,如果\(t\)的某个子串和\(s_i\)相等,则可以通过一次染色将这个子串中的字符都染成红色。 一个模式串可以用多次,\(t\)中的一个字符可以被染色多次,红色的字符再次

  • LeetCode 438 Find All Anagrams in a String 滑动窗口2022-08-01 17:34:19

    Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order. An \(Anagram\) is a word or phrase formed by rearranging the letters of a different word or phrase, typically using al

  • LeetCode 140 Word Break II 记忆化搜索 [Hard]2022-08-01 04:00:08

    Given a string s and a dictionary of strings wordDict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in any order. Note that the same word in the dictionary may be reused multiple ti

  • 7.292022-08-01 02:00:30

    CF954F 题意: 有一个\(3*m\)的格子,起点是\((2,1)\),终点是\((2,m)\),每一步可以向正右,右上,右下走,有多少种方案从起点走到终点? 额外有\(k\)个限制,每个形如在\([l_k,r_k]\)范围内,第\(a_k\)行不可进入。 \(k\leq 10^4,m\leq 10^{18}\) \(2\leq l_k\leq r_k\leq m,1\leq a_k\leq 3\) 题解

  • 题解[CF575E]Spectator_Riots2022-07-31 20:33:11

    题意 一个球场,可以看作 \(10^5\times10^5\) 的矩形,每个位置都是一个整点。一个位置 \((x,y)\) 位于球场内当且仅当 \(x\in[0,10^5]\and y\in[0,10^5]\) 。 有 \(n\) 个可能捣乱的黑粉,第 \(i\) 个在位置 \((x_i,y_i)\) 上,速度为 \(v_i\),即一秒内可能跑到任意一个距原来位置曼哈顿距

  • LeetCode/二分法综合2022-07-30 21:00:13

    1. 寻找两个正序数组的中位数 2. 两数相除 3. 快速幂 4. 搜索旋转排序数组 5. 数组中的逆序对 6. 在排序数组中查找元素的第一个和最后一个位置 class Solution { public: vector<int> searchRange(vector<int>& nums, int target) { return {find(nums,target,true),

  • LeetCode 238 Product of Array Except Self 前缀积&后缀积2022-07-30 20:35:18

    Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. You must write an algorithm t

  • AcWing 794. 高精度除法2022-07-29 20:33:14

    算法思路 模拟除法竖式。 流程 从最高位开始处理,上一次的余数 \(\times 10\) 再加上当前位上的数字(被除数,我们令它为 \(A\)); 往答案数组中压入 \(\lfloor \frac{A}{B} \rfloor\)(这里 \(B\) 表示除数),然后将余数更新为 \(A~mod~B\); 重复以上操作。 代码 #include <iostream> #inclu

  • LeetCode 204 Count Primes 欧拉(素数)筛2022-07-29 19:31:07

    Given an integer \(n\), return the number of prime numbers that are strictly less than \(n\). Solution 统计小于 \(n\) 的素数个数。这里用欧拉筛来筛素数,\(is\_prime\) 用来记录该数是否为素数,\(prime\) 来保存所有的素数 点击查看代码 class Solution { private: bo

  • LeetCode 108 Convert Sorted Array to Binary Search Tree DFS2022-07-29 06:31:26

    Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree. A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more tha

  • AcWing 791. 高精度加法2022-07-28 15:01:38

    观察题目 第一眼看题:这不就是大淼题 \(\text {A + B}\) 吗? 再一看,看到数据范围 \(1 \leq 整数长度 \leq 100000\),很显然,\(C++\) 中自带的数据类型肯定不行。 怎么办? 算法思路 观察到题目给出的整数长度数组存的下,因此我们可以先读入两个字符串,然后转成数组。 还记得小学一年级老师

  • AcWing 792. 高精度减法2022-07-28 15:00:42

    算法思路 与高精度加法大致相同,同样运用了“列竖式”的思想。 当然,加法中的“进位操作”要改成减法中的“退位操作”。 具体过程如下: 从最低位开始,用被减数的这一位减去减数的这一位; 判断是否构够减,若不够减(即减数的这一位大于被减数的这一位),则向高一位借一(被减数高一位减一,当前

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有