随笔分类 -  算法

[算法] 使用位运算遍历集合的子集
摘要:一、简介 对于使用状态压缩方法表示的集合A,如何遍历使用位运算遍历集合A的所有子集。 二、代码与注释 0. 符号假设 假设全集为S。S的元素个数为n。A为集合S的子集。 可以使用状态压缩方法加位运算表示集合A。 例如:S = {a, b, c, d},A = {a, b, d},那么可以使用状态10 阅读全文

posted @ 2022-09-20 14:39 刘好念 阅读(28) 评论(0) 推荐(0) 编辑

[算法] 埃式筛和欧拉筛选法简要介绍
摘要:一、摘要 敬告:本人博客将迁移至博客园刘好念的博客!!!以后将逐渐弃用CSDN。 素数筛是一种用于判断小于n的所有素数的算法。其中包括埃拉托斯特尼筛(埃式筛)和欧拉筛(线性筛、欧式筛)两类,本文将简要介绍埃式筛和欧式筛,并未对其中原理进行详细的介绍,若读者想了解两种筛选法的原理请查看算法学习笔记(1 阅读全文

posted @ 2021-11-21 20:25 刘好念 阅读(34) 评论(0) 推荐(0) 编辑

[STL] 标准二分算法模板 && lower_bound() upper_bound()代码解析
摘要:一、摘要 二分算法是经常使用的算法之一,熟练使用二分算法是一个程序员的基本素养。C++的<algorithm>头文件中存在lower_bound()和upper_bound()函数,支持在已排好序的容器中查找首个大于等于或者大于目标元素的迭代器位置。同时在有序容器类,例如set<>和map<>,也存 阅读全文

posted @ 2021-08-29 11:18 刘好念 阅读(80) 评论(0) 推荐(0) 编辑

[Algorithm] Binary Indexed Tree 树状数组模板
摘要:一、摘要 这是我个人的树状数组模板记录,对于其他人可能没有借鉴意义。 二、代码 // 树状数组类 // 下标从1开始 class BinaryIndexedTree{ public: // 构造函数,初始化数据数组c_,大小为总数据个数+1 BinaryIndexedTree(int n){ c_. 阅读全文

posted @ 2021-07-24 15:26 刘好念 阅读(2) 评论(0) 推荐(0) 编辑

[sort]O(n)复杂度查找中位数
摘要:前言 使用快速排序算法思想,查找数组中的第k大的数。复杂度为 O ( n ) O(n) O(n)。 代码 #include <iostream> #include <vector> #include <algorithm> // find median using namespace std; in 阅读全文

posted @ 2021-02-26 09:32 刘好念 阅读(4) 评论(0) 推荐(0) 编辑

[PAT]1101 Quick Sort (25 分)(样例2段错误原因)
摘要:一、题意 There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Th 阅读全文

posted @ 2019-08-30 18:58 刘好念 阅读(5) 评论(0) 推荐(0) 编辑

[leetcode]Leetcode中sort排序遇到的一些问题
摘要:转载自:https://www.cnblogs.com/flightless/p/10745318.html class Solution { public: static bool cmp(int a, int b){ return a>b; } int main(vector<int>& vec 阅读全文

posted @ 2019-08-27 08:47 刘好念 阅读(1) 评论(0) 推荐(0) 编辑

[LeetCode]1171. Remove Zero Sum Consecutive Nodes from Linked List
摘要:一、题意 Given the head of a linked list, we repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences. After doing 阅读全文

posted @ 2019-08-26 21:45 刘好念 阅读(5) 评论(0) 推荐(0) 编辑

[PAT]1119 Pre- and Post-order Traversals (30 分)(样例1未过,运行时错误原因)
摘要:一、题目 Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder an 阅读全文

posted @ 2019-08-15 10:54 刘好念 阅读(2) 评论(0) 推荐(0) 编辑

判断一个数是不是质数(素数),3种方式介绍
摘要:本文参考博文判断一个数是不是质数(素数),3种方式介绍,原文章解释的已经很详细,本问增加部分博主自己的理解。 一、概念介绍 质数:质数是指在大于1的自然数中,除了1和它本身以外不再有其他因数的自然数。特别的0,1不是质数。 二、方法介绍 1.最直接的方法 bool isPrime(int n){ i 阅读全文

posted @ 2019-08-14 16:51 刘好念 阅读(1574) 评论(0) 推荐(0) 编辑

[leetcode]32. Longest Valid Parentheses
摘要:题目描述 Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.样例 Example 1: 阅读全文

posted @ 2019-07-29 19:19 刘好念 阅读(2) 评论(0) 推荐(0) 编辑

[leetcode]10. Regular Expression Matching
摘要:题目 给定一个字符串 (s) 和一个字符模式 (p)。实现支持 '.' 和 '*' 的正则表达式匹配。 '.' 匹配任意单个字符。 '*' 匹配零个或多个前面的元素。 匹配应该覆盖整个字符串 (s) ,而不是部分字符串。 说明 s 可能为空,且只包含从 a-z 的小写字母。p 可能为空,且只包含从  阅读全文

posted @ 2018-12-17 20:29 刘好念 阅读(3) 评论(0) 推荐(0) 编辑

Hanoi汉诺塔
摘要:#汉诺塔# 代码 #include <iostream> #include <stdio.h> using namespace std; //汉诺塔函数,参数,n剩余棋子数,prime棋子初始所在杆,help移动棋子需要借助的杆,target最终移动的目标杆 void hanoi(int n, ch 阅读全文

posted @ 2017-12-22 23:24 刘好念 阅读(3) 评论(0) 推荐(0) 编辑

Eight Queen
摘要:八皇后问题 代码 #include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <cmath> using namespace std; int p[8][8]; // 棋盘数组 int c 阅读全文

posted @ 2017-12-19 21:46 刘好念 阅读(2) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示