leetcode contest weekly 351

AtCoder Regular Contest 123 C 1, 2, 3 - Decomposition

洛谷传送门 AtCoder 传送门 从低位往高位考虑。设当前个位为 $k$,暴力搜索这一位向上进 $i$ 位,设 $\left\lfloor\frac{n}{10}\right\rfloor - i$ 的答案为 $t$。 若 $t > 10i + k$ 显然就不可行,因为就算个位全部填 $1$ 也不 ......
Decomposition AtCoder Regular Contest 123

As a restaurant owner, write a professional email to the supplier to get these products every week: - Wine (x10) - Eggs (x24) - Bread (x12)

As a restaurant owner, write a professional email to the supplier to get these products every week: Wine (x10) Eggs (x24) Bread (x12) Dear Supplier, I ......

AtCoder Regular Contest 120 F Wine Thief

洛谷传送门 AtCoder 传送门 Hint 如果是一个环怎么做? Answer 由于是一个环,因此环上每个点对最终答案造成的贡献都相同。设 $f_{i,j}$ 为长度为 $i$ 的序列选 $j$ 个不相邻的点的方案数,则 $f_{i,j} = \binom{i-j+1}{j}$。应该很好理解,考虑 ......
AtCoder Regular Contest Thief Wine

【哈希表】LeetCode 767. 重构字符串

题目链接 767. 重构字符串 思路 先用哈希表统计出出现次数最多的字符,如果这个次数大于一半,说明这个字符总会挨在一起,直接返回 ""。 如果不超过一半,则先把字符填在偶数位置(先填出现次数最多的字符),偶数位置填满了再填奇数位置。 代码 class Solution { public Strin ......
字符串 字符 LeetCode 767

【DP】LeetCode 740. 删除并获得点数

题目链接 740. 删除并获得点数 思路 分析动态规划题目的时候只需要考虑最后一个阶段,因为所有的阶段转化都是相同的,考虑最后一个阶段容易发现规律 在数组的动态规划问题中,一般 dp[i] 都是表示以 nums 以前 i 个元素组成(即 nums[i - 1])的状态;dp[i][j] 分别表示以 ......
点数 LeetCode 740

AtCoder Regular Contest 125 E Snack

洛谷传送门 AtCoder 传送门 很棒的 flow 题,考虑建二分图。 源点向每种零食连边权为 $a_i$ 的边,每种零食向每个孩子连边权为 $b_j$ 的边,每个孩子向汇点连边权为 $c_j$ 的边,这个图的最大流就是答案。 直接跑最大流肯定 T,考虑最大流等价于求这个图的最小割,因此转而求最小 ......
AtCoder Regular Contest Snack 125

AtCoder Regular Contest 126 D Pure Straight

洛谷传送门 AtCoder 传送门 很不错的状压。 考虑先把最后作为答案的数聚到一起,再算它们的逆序对个数。 设 $f_S$ 为当前选的数集合为 $S$ 的答案。有转移: 选 $a_i$,答案加上之前选的比它大的数; 不选 $a_i$,此时需要把左边的数或者右边的数往中间挪一个,答案加上左右两端的最 ......
Straight AtCoder Regular Contest Pure

LeetCode 152. 乘积最大子数组

原题解 ###题目 约束 ###题解 class Solution { public: int maxProduct(vector<int>& nums) { int maxF = nums[0], minF = nums[0], ans = nums[0]; for (int i = 1; i < ......
乘积 数组 LeetCode 152

[LeetCode] 2336. Smallest Number in Infinite Set

You have a set which contains all positive integers [1, 2, 3, 4, 5, ...]. Implement the SmallestInfiniteSet class: SmallestInfiniteSet() Initializes t ......
LeetCode Infinite Smallest Number 2336

SMU Spring 2023 Trial Contest Round 9

A. Wrong Subtraction 在k次操作里, 将n的最后一位数减1,如果是0就去掉,模拟一下就好了. #include <bits/stdc++.h> //#define inf 0x3f3f3f3f #define endl '\n' #define int long long usi ......
Contest Spring Round Trial 2023

SMU Spring 2023 Trial Contest Round 10

SMU Spring 2023 Trial Contest Round 10 A - Remove Duplicates #include<bits/stdc++.h> using namespace std; typedef pair<int,int>PII; typedef pair<strin ......
Contest Spring Round Trial 2023

[LeetCode] 2418. Sort the People

You are given an array of strings names, and an array heights that consists of distinct positive integers. Both arrays are of length n. For each index ......
LeetCode People 2418 Sort the

【LeetCode动态规划#13】买卖股票含冷冻期(状态众多,比较繁琐)、含手续费

最佳买卖股票时机含冷冻期 力扣题目链接(opens new window) 给定一个整数数组,其中第 i 个元素代表了第 i 天的股票价格 。 设计一个算法计算出最大利润。在满足以下约束条件下,你可以尽可能地完成更多的交易(多次买卖一支股票): 你不能同时参与多笔交易(你必须在再次购买前出售掉之前的 ......
手续费 LeetCode 手续 状态 股票

LeetCode 1643. 第 K 条最小指令

康托展开 一开始无脑枚举全排列, 果断超时, 还是得看看如果降低计算量。 题目destination = [2,3], 相当于2个V, 3个H, 输出全排列去重后的对应位置字典序列内容。 忽略去重 则问题为全排列, 所有可能为: $$ (\sum destination)! = (2+3)! = 5 ......
指令 LeetCode 1643

AtCoder Beginner Contest 159

AtCoder Beginner Contest 159 https://atcoder.jp/contests/abc159 EF 是打基础的好题 D - Banned K #include <bits/stdc++.h> #define ll long long using namespace ......
Beginner AtCoder Contest 159

leetcode调研version0

这是我第一次发博客,所以许多功能还不太会使用。前几次的随笔既当作记录,也当作自己的练习。 最近想要刷leetcode,纠结用哪种语言(我自己学过c/c++, python, fortran, Java),所以前期做了一些调研,在此记录一下。 c语言: 网址:https://github.com/be ......
leetcode version0 version

leetcode 607 銷售員

銷售員 select s.`name` from salesperson s left join orders o on s.sales_id=o.sales_id left join company c on o.com_id=c.com_id and c.name='RED' group by ......
leetcode 607

SMU Spring 2023 Trial Contest Round 10

A. Remove Duplicates #include <bits/stdc++.h> using namespace std; #define int long long int read() { int x = 0, f = 1, ch = getchar(); while ((ch < ' ......
Contest Spring Round Trial 2023

leetcode 595 大的國家

大的國家 select `name`, population, area from World where area >= 3000000 or population >= 25000000 ......
leetcode 595

【DP】LeetCode 213. 打家劫舍 II

题目链接 213. 打家劫舍 II 思路 分析动态规划题目的时候只需要考虑最后一个阶段,因为所有的阶段转化都是相同的,考虑最后一个阶段容易发现规律 在数组的动态规划问题中,一般 dp[i] 都是表示以 nums 以前 i 个元素组成(即 nums[i - 1])的状态;dp[i][j] 分别表示以 ......
打家劫舍 LeetCode 213 II

leetcode 586 訂單最多的客戶

訂單最多的客戶 select customer_number from Orders group by customer_number having count(order_number) = ( select count(order_number) from Orders group by cus ......
leetcode 586

leetcode 584 尋找用戶推薦人

尋找用戶推薦人 select name from customer where referee_id <> 2 or referee_id is null ......
leetcode 584

leetcode 570 至少有5名直接下屬的經理

至少有5名直接下屬的經理 子查詢 select `name` from Employee where id in ( select managerId from Employee group by managerId having count(managerId) >= 5 ) 自連接 select ......
少有 leetcode 570

[LeetCode] 1342. Number of Steps to Reduce a Number to Zero 将数字变成 0 的操作次数

Given an integer num, return the number of steps to reduce it to zero. In one step, if the current number is even, you have to divide it by 2, otherwi ......
Number LeetCode 次数 数字 Reduce

【DP】LeetCode 198. 打家劫舍

题目链接 198. 打家劫舍 思路 分析动态规划题目的时候只需要考虑最后一个阶段,因为所有的阶段转化都是相同的,考虑最后一个阶段容易发现规律 在数组的动态规划问题中,一般 dp[i] 都是表示以 nums 以前 i 个元素组成(即 nums[i - 1])的状态;dp[i][j] 分别表示以 num ......
打家劫舍 LeetCode 198

【DP】LeetCode 1277. 统计全为 1 的正方形子矩阵

题目链接 1277. 统计全为 1 的正方形子矩阵 思路 分析动态规划题目的时候只需要考虑最后一个阶段,因为所有的阶段转化都是相同的,考虑最后一个阶段容易发现规律 在数组的动态规划问题中,一般 dp[i] 都是表示以 nums 以前 i 个元素组成(即 nums[i - 1])的状态;dp[i][j ......
正方形 正方 矩阵 LeetCode 1277

LeetCode 148. 排序链表

前置题目 21. 合并两个有序链表 原题解 ###题目 约束 ###题解 ####方法一 class Solution { public: ListNode* sortList(ListNode* head) { return sortList(head, nullptr); } ListNode* ......
LeetCode 148

【LeetCode动态规划#12】详解买卖股票I~IV,经典dp题型

买卖股票的最佳时机 力扣题目链接(opens new window) 给定一个数组 prices ,它的第 i 个元素 prices[i] 表示一支给定股票第 i 天的价格。 你只能选择 某一天 买入这只股票,并选择在 未来的某一个不同的日子 卖出该股票。设计一个算法来计算你所能获取的最大利润。 返 ......
题型 LeetCode 股票 经典 动态

[Week 18] 每日一题(C++,动态规划,线段树,数学)

[Daimayuan] T1 最长公共子序列(C++,DP,二分) 给出从 $1$ 到 $n$ 的两个排列 $P_1$ 和 $P_2$,求它们的最长公共子序列。 输入格式 第一行是一个正整数 $n$。 接下来两行,每行为 $n$ 个数,为自然数 $1,2,…,n$ 的一个排列。 输出格式 一个数,即 ......
线段 数学 动态 Week 18

AtCoder Beginner Contest 158

AtCoder Beginner Contest 158 https://atcoder.jp/contests/abc158 基础不牢,地动山摇 D - String Formation 一个小小的STL应用 #include <bits/stdc++.h> #define ll long lon ......
Beginner AtCoder Contest 158