leetcode contest weekly 351
7-009-(LeetCode- 309) 最佳买卖股票时机含冷冻期
1. 题目 读题 考查点 2. 解法 思路 代码逻辑 具体实现 1 1 3. 总结 ......
2023 Hubei Provincial Collegiate Programming Contest
链接:https://codeforces.com/gym/104337 C 画个图看看,复杂度 $O(1)$。 C++ Code #include "bits/stdc++.h" using namespace std; using i64 = long long; int main() { io ......
LeetCode/移动石子直到连续
###1. 移动石子直到连续(三个石子) class Solution { public: vector<int> numMovesStones(int a, int b, int c) { int x = min({a, b, c}); int z = max({a, b, c}); int y ......
AtCoder Regular Contest 117 D Miracle Tree
洛谷传送门 AtCoder 传送门 第一步就没想到 可以考虑化简限制。设所有点按 $E_i$ 从小到大排序后顺序是 $p_1,p_2,...,p_n$。发现只需满足 $E_{p_{i+1}} - E_{p_i} \ge \operatorname{dis}(p_i, p_{i+1})$。证明是对于任 ......
AtCoder Beginner Contest 231
A - Water Pressure #include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; printf("%.6lf\n" , n / 100.0 ); return 0; } B - Election ......
Educational DP Contest
Educational DP Contest ATcoder_link 夯实基础的好东西 I 记录一下此时第 i 个有多少概率小于等于 j 的就可以了。 #include<bits/stdc++.h> using namespace std; const int N=3005; #define db ......
[LeetCode] 1033. Moving Stones Until Consecutive
There are three stones in different positions on the X-axis. You are given three integers a, b, and c, the positions of the stones. In one move, you p ......
AtCoder Beginner Contest 300
A - N-choice question (abc300 a) 题目大意 给定一个元素互不相同的数组$c$和 $a,b$,找到 $i$使得 $c_i = a + b$ 解题思路 直接for循环寻找即可。 神奇的代码 ```cpp #include using namespace std; usin ......
leetcode_D10_136只出现一次的数字
1.题目 2.解一 leetcode官方解法,主要用到了两个知识:第一个是reduce函数,需要注意的是在python3中,需要 通过“ from functools import reduce ”从模块中调用该函数;第二个知识是位运算中的异或运算,主要有以下计算法则。 有了这两个补充知识,该题目就 ......
AtCoder Regular Contest 116 F Deque Game
洛谷传送门 AtCoder 传送门 很强的博弈 + 性质题。下文令 A 为 Takahashi,B 为 Aoki。 发现单独考虑一个序列 $a_1,a_2,...,a_n$: 若 $n \bmod 2 = 0$: 若 A 为先手,答案为 $\max(a_{\frac{n}{2}}, a_{\frac ......
2023-04-28 LeetCode精选题目20道附我的Java实现
LeetCode精选题目20道 1.56.合并区间 贪心 给出一个区间的集合,请合并所有重叠的区间。 示例 1: 输入: intervals = [[1,3],[2,6],[8,10],[15,18]] 输出: [[1,6],[8,10],[15,18]] 解释: 区间 [1,3] 和 [2,6] ......
AtCoder Regular Contest 123 E Training
洛谷传送门 AtCoder 传送门 不妨假设 $B_X \le B_Y$。设 $f(x) = A_X + \frac{x}{B_X}, g(x) = A_Y + \frac{x}{B_Y}, F(x) = \left\lfloor{f(x)}\right\rfloor, G(x) = \left\l ......
C语言刷leetcode——并查集
概述 https://leetcode.cn/problems/number-of-provinces/solution/python-duo-tu-xiang-jie-bing-cha-ji-by-m-vjdr/ 基本概念 并查集是一种数据结构 并查集这三个字,一个字代表一个意思。 并(Union ......
vscode-leetcode
vscode 里写 leetcode 需要的插件xavier-cai.vscode-leetcode-cpp-debug, leetcode.vscode-leetcode LeetCode C++ Debugger.Delete Temporary Contents置为false ctrl+shi ......
LeetCode 241 为运算表达式设计优先级
LeetCode | 241.为运算表达式设计优先级 给你一个由数字和运算符组成的字符串 expression ,按不同优先级组合数字和运算符,计算并返回所有可能组合的结果。你可以 按任意顺序 返回答案。 生成的测试用例满足其对应输出值符合 32 位整数范围,不同结果的数量不超过 104 。 示例 ......
【二分查找】LeetCode 153. 寻找旋转排序数组中的最小值
题目链接 153. 寻找旋转排序数组中的最小值 思路 首先分析一下旋转数组可能有的状态: 左 < 中 < 右,此时最小值肯定在左边,应当收缩右边界 左 < 中,中 > 右,此时最小值肯定在右半段,应当收缩左边界 左 > 中,中 < 右,此时最小值肯定在左半段,应当收缩右边界 分析这三种状态可以发现, ......
[LeetCode] 1031. Maximum Sum of Two Non-Overlapping Subarrays
Given an integer array nums and two integers firstLen and secondLen, return the maximum sum of elements in two non-overlapping subarrays with lengths ......
LeetCode 双指针
15. 三数之和 (为0) 下标不能是重复的,必定右 i<l<r 1、先对数组排序(从小到大) 2、外层 i 遍历 如果 nums[i] > 0 ,整个 nums[] 后面的必定无法有三元组为0(排过序了,后面的 nums[l] nums[r] 都会大于0)。break。 如果 nums[i] = ......
【LeetCode动态规划#14】子序列系列题(最长递增子序列、最长连续递增序列、最长重复子数组、最长公共子序列)
最长递增子序列 力扣题目链接(opens new window) 给你一个整数数组 nums ,找到其中最长严格递增子序列的长度。 子序列是由数组派生而来的序列,删除(或不删除)数组中的元素而不改变其余元素的顺序。例如,[3,6,2,7] 是数组 [0,3,1,6,2,2,7] 的子序列。 示例 1 ......
AtCoder Regular Contest 126 E Infinite Operations
洛谷传送门 AtCoder 传送门 算是对这篇博客的补充吧。 设 $a_1 \le a_2 \le \cdots \le a_n$。 发现最优操作中一定是对相邻的数进行操作,因为如果 $a_j$ 想把 $x$ 给 $a_i$($i < j$),最优是依次操作 $(j-1,j,x),(j-2,j-1, ......
【哈希表】LeetCode 895. 最大频率栈
题目链接 895. 最大频率栈 思路 很容易想到使用 map:valToFreq 来记录每个值出现的频率,这是没问题的,但关键是如何通过频率寻找到应该返回的数。 这时候我想到再加一个 map:freqToVal 来记录每个频率中出现的数字,为了符合题目返回最接近栈顶的元素的要求,freqToVal ......
代码随想录Day38-Leetcode509. 斐波那契数,70. 爬楼梯,746. 使用最小花费爬楼梯
咳咳, 因为找实习+摆导致时间被浪费大半; 先从动态规划学起吧,之前的慢慢补。 理论基础 动态规划的解题步骤 1.确定dp数组及对应下标的含义 2.确定dp的状态转移方程(递推公式) 3.确定dp数组如何初始化 4.确定dp遍历顺序 5.距离推导dp数组验证 509. 斐波那契数 题目链接:http ......
AtCoder Regular Contest 112 F Die Siedler
洛谷传送门 AtCoder 传送门 感觉太人类智慧了。 设 $A = (c_1,c_2,...,c_n)$ 表示当前每种牌的数量,$f(A)$ 为状态 $A$ 只进行换牌操作最终最少剩下几张牌。 $f(A)$ 是可以贪心求出的,因为策略必然是能换则换。 并且我们发现依次换 $2,3,...,n,1$ ......
【TreeMap】LeetCode 1438. 绝对差不超过限制的最长连续子数组
题目链接 1438. 绝对差不超过限制的最长连续子数组 思路 本题一看就是一个要用到滑动窗口的题目,难点在于如何快速求窗口中的最大值和最小值。幸好 Java 中有 TreeMap 这个数据结构,它在构成 map 映射的同时,还能够保证其中的元素有序,这样就能很方便求得窗口中的最大值和最小值了。 代码 ......
leetcode 608 樹節點
樹節點 select id, 'Root' as Type from tree where p_id is null union select id, 'Inner' as Type from tree where id in ( select distinct p_id from tree whe ......
1351. 统计有序矩阵中的负数(leetcode)
https://leetcode.cn/problems/count-negative-numbers-in-a-sorted-matrix/ 1351. 统计有序矩阵中的负数 1.二分法:把每一行进行一遍二分,找到正数与负数的边界,且此时grid[i][mid]也为负数,即边界下标的对应值是负数的 ......