算法
文章平均质量分 87
Gong JX
SAP野生顾问
展开
-
单调栈的应用
1.定义从栈底元素到栈顶元素呈单调递增或单调递减,栈内序列满足单调性的栈;2.实例Some of Farmer John'sNcows (1 ≤N≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cow...原创 2021-09-01 16:21:03 · 97 阅读 · 0 评论 -
线段树模板 敌兵布阵 HDU-1166
线段树是一种二叉搜索树,它将每一个结点划分成一些单元区间由上图可以看出,线段树是平衡二叉树,最后的子节点数目为N,即整个线段区间的长度。时间复杂度为O(logN)。而未优化的空间复杂度为2N,但是根据上图,即使5号是叶子结点,想要存下6号的两个孩子结点必须将空间扩充到13,所以存下所有的子节点2N的空间是不够用的以此测试当区间长度为36时,3N也是不够用的,所以实际应用时一般还要开4N的数组以免越界。线段树可以很快速的知道某一个区间内的叶子结点的情况,和也好最大值也好,把叶子结...原创 2021-03-10 09:59:08 · 78 阅读 · 0 评论 -
迷宫路径,输出最短路径(BFS)
题目:POJ - 3984今天阿聪来到了一个滑雪胜地滑雪,但是这个时候前面出现了一座迷宫挡住了他的去路。 坚定的阿聪一定要穿过这座迷宫去滑雪! 为了方便起见,我们定义一个二维数组来表示迷宫:int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1...原创 2020-03-11 15:44:42 · 382 阅读 · 0 评论 -
用并查集找出病源
例题是: poj-1611 这是一道关于疫情的题,非常适合出现在这个时候....原题是:Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimi...原创 2020-03-08 21:07:55 · 367 阅读 · 0 评论 -
深度优先搜索 例: Red and Black
题目:There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But h...原创 2020-02-11 20:59:39 · 137 阅读 · 0 评论 -
VUA-156 Ananagrams (STL应用 map)
DescriptionMost crossword puzzle fans are used toanagrams--groups of words with the same letters in different orders--for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have ...原创 2018-07-26 21:06:01 · 130 阅读 · 0 评论 -
kmp算法(模板)
KMP 算法的关键在于初始化next[ ] 数组void getnext(char *b){ int len=strlen(b); / / 待匹配字符串的长度 next[0]=next[1]=0; / /初始化第一个数和第二个数 for(int i = 1; i < len ; i++){ ...原创 2018-08-11 17:09:09 · 561 阅读 · 1 评论