摘要:
https://www.acwing.com/problem/content/245/ 线段树维护一个$01$序列,$b[i] = 1$表示身高为$i$的牛是否出现过,倒着扫一遍, 每次找到第$a[i] + 1$个$1$(未出现过的身高)就是当前牛的身高,并把该位置变成$0$ 线段树上二分查找即可 阅读全文
摘要:
题目链接:https://www.acwing.com/problem/content/description/241/ 并查集的一个重要功能就是动态维护具有传递性的关系, 比如:相等,奇偶性等等 如果传递关系只有一种,比如相等,那就使用普通的并查集来维护即可 如果传递关系不只有一种,比如本题的奇偶 阅读全文
摘要:
https://www.acwing.com/problem/content/240/ 除了位于哪个集合的$fa[i]$之外,还要维护一个$dis[i]$,表示该元素在当前集合的深度 路径压缩的时候,沿途更新之前合并过去的元素的$dis$, 同时还要维护集合的大小$sz$, 用于更新$dis$ #i 阅读全文
摘要:
https://www.acwing.com/problem/content/239/ 离线,离散化 \(i,j\) 的编号, 先处理 \(x_i = x_j\) 的操作,将 \(i,j\) 合并, 再查询 \(x_i = x_j\) 的操作,看 \(i,j\) 是否在同一个集合里 #include 阅读全文
摘要:
https://www.acwing.com/problem/content/173/ 折半搜索经典题目 按重量从大到小排序搜索 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cm 阅读全文
摘要:
题目链接:https://www.acwing.com/problem/content/170/ 剪枝剪枝剪枝。。 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cmath> #i 阅读全文
摘要:
https://www.acwing.com/problem/content/description/169/ 剪枝剪枝还是剪枝 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cm 阅读全文
摘要:
题目链接:https://www.acwing.com/problem/content/description/166/ 拓扑排序: 对于图中每条边$(x,y)$, 如果在序列$A$中,\(x\) 始终出现在 \(y\) 的前面,则称序列 \(A\) 为该图的拓扑序 用 \(bfs\) 求解拓扑序, 阅读全文
摘要:
题目链接:https://www.acwing.com/problem/content/160/ 最小表示法模板题 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cmath> #i 阅读全文
摘要:
题目链接:https://www.acwing.com/problem/content/147/ 贪心策略: 将商品按时间排序,维护一个小根堆,如果当前商品过期天数等于堆中商品数量, 且当前商品价值大于堆顶商品,则将堆顶弹出,插入当前商品; 如果当前商品过期天数大于堆中商品数量,则之间将商品插入堆中 阅读全文