版本比较
刷题记
正文
增加 55 行删除 1 行
202 行未改动全部展开203204205206207208209210211212213214215216211217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268202 行未改动全部展开- 启发式合并的精髓在于只遍历较小的【数据结构】,并且每次会增长一倍,故可以保证 $\log$。
- 对于删除相邻的相同字符,考虑变成相邻的不同字符(例如删除相邻的 0,变成删除 01 或 10)。为什么呢?因为删去相邻的会给某种字符减少两个,而不相同都会减,便于统计。
- 要求满足拟序关系可以考虑维护相应最值。
- AC 自动机的题目对于标记一定要考虑是否需要上传。
- 将字典序小于转化为包含。
### 贪心> 注意到贪心是很多算法的核心思想,无论是在正解或水分中都是不可或缺的。
#### P4090##### P4090并不容易注意到,收不到礼物的奶牛肯定是一段连续的后缀,但是怎么想到的呢?因为题目提示了插入到 $c_i$ 只奶牛前面。想到这个之后考虑对于每只奶牛能不能收到礼物,考虑一头牛是否能收到礼物。
然后糊了很久没有想到。开合,原来是贪心吗?不会证,略。
##### [P13600 [NWRRC 2022] Computer Network](https://www.luogu.com.cn/problem/P13600)
It seems like a very complex problem, but actually it is not that hard as my imagination.
We can find it will be a tree witch the computers have only one father and the computer's wire has $k$ sons after the construction of the network. Then we discover the more one computer's depth low, the more frequencies it be passed by. So we can get a greedy strategy that we can let the depth of the computer with lower $d$ lower. And then we find another conclusion is we can make the computer connect the lowest milliseconds it has to pass by. But why the method is correct ? I think because it can make sure the local optimality if we must to choose one computer to be it son.
So we use the priority queue to uphold this process and count the answer meanwhile.
##### [P2949 [USACO09OPEN] Work Scheduling G](https://www.luogu.com.cn/problem/P2949)
It is a application of regret-greedy algorithm. But I was not identify it at first. You can find every time is same, so we can use greedy. And we may have to replace the choice before and get a better answer. So it is regret-greedy algorithm.
The difficulty of it is only that we can't identify it quickly, but we will find it is not hard if you know this is a regret-greedy porblem.
##### [P9977 [USACO23DEC] Bovine Acrobatics S](https://www.luogu.com.cn/problem/P9977)
It is a simple problem, but my thinking is stupid. First, we need to find some attribute in this problem. We know that we only care about the top cow's weight of a tower of cow because only the top cow can affect what cow can be added in this tower of cow. And then, we can find we must make sure the top cow's weight of the tower of cow as big as possible because it can lead the answer isn't worse. Then I find a brute-force method that we use the priority queue to uphold all top cows' weight and quantity. We can sort all cows make their weight not increasing and choose the top $m$ cows as the initial towers of cows. That we can choose as much as possible with current weight because it ensures answer not worse, omitting proof process. Fine implementation can pass.
### 线段树> 没什么好说的,直接上 ds 就完了。
##### [P6492 [COCI 2010/2011 #6] STEP](https://www.luogu.com.cn/problem/P6492)考虑需要合并左右两个区间的答案需要什么信息,然后就做完了。
##### [CF19D Points](https://codeforces.com/problemset/problem/19/D)考虑线段树二分,没有想到最大值满足就一定有满足的。
##### [P2824 [HEOI2016/TJOI2016] 排序](https://www.luogu.com.cn/problem/P2824)注意到只有一次查询,考虑离线下来。
你会发现不方便直接计算答案,进而去考虑对于一个答案去 check 是否小于等于这个位置的值。你会发现如果 check 这个东西对于大于等于 $x$ 的全都是等价的,设为 1,其余的设为 0,发现对于 01 序列的排序其实就是把 0 放前面,1 放后面,然后区间推平加区间查询,线段树维护即可,思路较为巧妙。
### DP> 个人认为我的 DP 思想以及做题时的想法弱于贪心,故有了这个专题。
##### [P1439 两个排列的最长公共子序列](https://www.luogu.com.cn/problem/P1439)
考虑复杂度允许 $\mathcal{O}(n\log n)$,但是你会发现最长公共子序列不好直接维护,故考虑转化为其他的形式。
观察到这是一个排列,考虑将其中每个数的出现位置记录下来。
合完题解,发现没有想到转化为最长上升子序列,想到了就很简单,因为 $\mathcal{O}(n\log n)$ 求最长公共子序列显然好求。
##### [P1004 [NOIP 2000 提高组] 方格取数](https://www.luogu.com.cn/problem/P1004)
考虑到两个走到相同的位置需要花费的步数相同,故考虑将步数当作状态,同时记录两个同时走的位置。