当前位置:网站首页>总结一些最近见到的 TRICK
总结一些最近见到的 TRICK
2022-07-23 17:25:00 【lovesickman】
总结一些最近见到的 TRICK:
并查集 O ( n + m ) O(n+m) O(n+m) 解决区间合并问题 3115. 疯狂的馒头。
滑动窗口枚举到 i i i 点时求 [ i − k , i − j ] [i-k,i-j] [i−k,i−j] 中的最值。
单调栈求距离自身最近的最右的某个值需要倒序。
枚举矩阵有 4 个自由度,可以通过枚举上下两个边界将矩阵变成 1 维的,在用二分或双指针实现 O ( n 3 ) O(n^3) O(n3) 遍历。
给定一个 n ∗ m n*m n∗m 的矩阵 求一个 c ∗ c c*c c∗c 大小的子矩阵中的最值。可以用二维滑动窗口实现。核心思路还是二维看成一维。先每一行求一个长度为 c c c 的滑动窗口,在每一列求一个长度为 c c c 的滑动窗口,最后枚举答案。
DP的本质是组合数学,可以通过0/1背包,完全背包的思路推导组合数学中组合数公式和可重集组合公式。
区间合并问题要记住一些智慧数据,区间合并可以 O ( n ) O(n) O(n) 实现,左端点从小到大排序。
unorder_map,均摊 O ( 1 ) , 最坏 O ( n ) O(1),最坏O(n) O(1),最坏O(n) , 快排是均摊 O ( n l o g n ) , 最坏 O ( n 2 ) O(nlogn),最坏O(n^2) O(nlogn),最坏O(n2)可以通过初始化大小防止被卡,(CF除外,需要mt19937)
区间合并有3种做法,并查集,贪心,离散化+差分。
刷表法可以求解背包问题 K K K 优解。
给定一个矩阵,求带限制的最大的子矩阵的面积,还是每一行单独考虑,跑 n n n 次 单调栈。
给一堆东西染色求最后的颜色,可以倒着考虑。
很多求树上问题的思路来源都是 树的重心 还有 树的直径。
许多问题要逐步分解,如果没有思路,可以尝试,画图找规律和性质,二分答案转成判定,等
双指针关键(其实写多了就没啥关键不关键的了),定义 j = f [ i ] j = f[i] j=f[i] , 如果 i i i 确定之后, j j j 只能单调向左(没见过)/右移动,就可以直接双指针了。while循环里边是否定条件。
矩阵上求最值除了求 n n n 遍单调队列还可以二维 S T ST ST 表。
线段树指针写法,new 超慢,可以定义静态的节点再用一个移动一位。
L C A LCA LCA 有 t a r j a n tarjan tarjan ,并查集,倍增 三种写法, 至少会背一个。
如果两个区间 [ l 1 , R 1 ] , [ R 1 + 1 , R 2 ] [l_1,R_1],[R_1+1,R_2] [l1,R1],[R1+1,R2] 想多空一个间隔,可以下标乘2。
有点sb二维一维化可以传二维数组的一维进去,但是要是按照列来做呢?要么重写一个,要么把数据先按照列拿出来,再传进去。
有的时候我会把DP状态表示的太死,然后发现状态转移方程完全写不出来,可以退一步,让DP多带一维信息,再试试。比如,一定选,一定不选。
可行性DP,可以用 bitset 装逼实现。
一些已知中序遍历和xx遍历,输出bfs序的题,在dfs里边穿一个层,就能直接记录下bfs序。
笛卡尔树 。
边栏推荐
- LM393 low power dual voltage comparator parameters, pins, application details
- Source code analysis of ThreadPoolExecutor
- 数据链路层 -------- 以太网 和 ARP
- 多线程与高并发day11
- Tree learning summary
- not all arguments converted during string formatting
- @JPA annotation in entity
- Rapid establishment of devstack cloud computing platform
- Error reporting caused by the use of responsebodyadvice interface and its solution
- 正则化不同导致的tuple错误
猜你喜欢

Google正在改进所有产品中的肤色表现 践行“图像公平”理念

去中心化存储面临的挑战

Tcl 语言之Synopsys Tcl篇(3)(数字IC)

还在用Xshell?你out了,推荐一个更现代的终端连接工具

lendingclub贷款状态loan status业务详解-current,charge off,issued,Fully Paid,grace period

Design of UART interface based on FPGA
![Paddlenlp's UIE classification model [taking emotional propensity analysis news classification as an example] including intelligent annotation scheme)](/img/00/e97dcac9f07e5d4512614536a17cd4.png)
Paddlenlp's UIE classification model [taking emotional propensity analysis news classification as an example] including intelligent annotation scheme)

UPC 2022 summer personal training game 12 (number of combinations b)

Building virtual private network based on softther

How to understand: common code block, construction block, static block? What does it matter?
随机推荐
Weights & Biases (一)
多线程与高并发day11
FPGA implementation of IIC bus of IIC protocol (II) (single read / write drive)
人脸识别系统技术方案
Ros2 self study notes: rviz visualization tool
Challenges of decentralized storage
正则化不同导致的tuple错误
.NET Core 实现后台任务(定时任务)Longbow.Tasks 组件(三)
Labyrinth DP integration
Implementation of SPI communication protocol based on FPGA
Learn and understand Architecture Design from business development
FPGA实现IIC协议(二)之IIC总线的FPGA实现(单次读写驱动)
软件测试岗位就业竞争压力大,985毕业的“打工人“同样存在苦不堪言
@JPA annotation in entity
电子元件-电阻
Rapid establishment of devstack cloud computing platform
The first layer of OSI model: physical layer, the cornerstone of existence!
Mbio | the sun Chaomin formation of Ocean Institute has verified in situ the new pathway of microbial mediated elemental sulfur formation in the deep sea
CTF misc learning summary "suggestions collection"
C language small project - address book (static version + dynamic version + file version)