Minute Osamu:
Divide and conquer divide and conquer, divide and rule; divide and conquer algorithm is a big problem into several smaller-scale problems and resolve them, and finally solve the overall problem by solving sub-problems.
Use divide and conquer algorithm in OI mainly in two aspects:
1. Based on binary search, find-thirds of use
2. The use of the title is divided into finer sub-problem
We will explain these two aspects of order
Half -
Is bipartite nature: a sorted range determined within a border, the border side of the element satisfies certain properties, while the other side is not satisfied;
Therefore, to solve the following two points are often used types of problems:
1. A simple binary search
2. binary answer (i.e., a monotonic function of seeking the most value satisfying certain properties)
3. The most value of most value (the most common type of half title)
Understand half from high level:
It is actually a binary determined boundary;
Dichotomy needs orderly and can be ordered size, it can also be other strange issues;
The most value most value: the largest minimum, the smallest maximum => want half => excellent writing;
Binary template:
I really do not like talking about write-half
Noip2012 by classroom
Using differential thought marking, then the prefix and obtains again the number of classrooms by day; O (n + m);
Then two points, O (n) comparing the legality qwq
Plus line ignorant force
Suddenly Amway website:
U 1 ~ num within the range, the number being divisible by the number x;
V 1 ~ num within the range, the number being divisible y;
Within the range of W 1 ~ num, x * y is a number divisible by number;
Complexity of O (log ] 3/2 N )
Eps:
First say: 1e-8 is 10 ^ -8;
Non-unimodal function:
Each peak cut out, and then each piece of seeking an optimal;
How to cut peak it, as long as you cut thin enough, each of which is a peak
Len: the length of each segment
Block-
√n first sub-block length n of the array, each of length approximately √n;
1. simple idea, violence.
L find where a, r in which one
Case 1: l, r in the same complexity does not exceed a o (√n)
2: l, r in the neighboring blocks in the complex of not more than o (2√n);
3: l, r from a distance; L, where r is computed block, marking the remaining intermediate block; up to play o (√n) blocks;
2. Sort gods orz
First block, to sort the data in the block when the block,;
Inquire:
- In the same tranches in O (√n) for violence
- Neighboring block O (2√n)
- Non-adjacent;
首先在a数组中查询左端点l所在块中,l右侧有多少满足的
同理右端点r也跑一下;
然后对于中间的块,每一个块都在b数组中跑一个二分就好了呢qwq
暴力加加在a上,然后再排序;其他的与1的加相同;
修改:先将l所在块和r所在块进行暴力并且在b数组中重新排序,其他中间的块打标记,当查询这个块时,不再查询x,而是查询 x-此块打的标记;
3.精髓:一个long long的整数最多开方6次,0开方为0,1开方为1;
先分块,对区间分√n块,每次开方时,for l~r,全部开方,当某个块只有0或1时,打个标记,就不用再开方了;
复杂度:O(6n);
记录离当前颜色最近的相同颜色的球的位置;
最后一句查询可以用2来做
修改:对每个颜色维护一个set;
把每个颜色丢进去;????
要满足于代码短,代码优秀;
搜索:
最短路=>广搜
求所有解=>深搜 干净代码+清晰思路
广搜的节点要开多一点;不要如此吝啬;
一般用于求最优解
轮次搜:
q0和q1交替搜索,然后直到交头;会减少垃圾节点;
迭代加深搜索:
搜到d层就不搜了,如果没有解,深度d++;
适合很深很宽的搜索树;
枚举完深度,选用深搜
开始连接:https://www.cnblogs.com/zhuier-xquan/p/10991869.html
当你觉得题面很复杂,数据范围又很小,考虑搜索;
莫得剪枝↑
剪枝1:现在体积超过n,无需再跑,直接return;
剪枝2:当前算的表面积比我们目前求得最优解大,return;
强夸剪枝二!