摘要:一、简介 对于使用状态压缩方法表示的集合A,如何遍历使用位运算遍历集合A的所有子集。 二、代码与注释 0. 符号假设 假设全集为S。S的元素个数为n。A为集合S的子集。 可以使用状态压缩方法加位运算表示集合A。 例如:S = {a, b, c, d},A = {a, b, d},那么可以使用状态10
阅读全文
摘要:一、摘要 敬告:本人博客将迁移至博客园刘好念的博客!!!以后将逐渐弃用CSDN。 素数筛是一种用于判断小于n的所有素数的算法。其中包括埃拉托斯特尼筛(埃式筛)和欧拉筛(线性筛、欧式筛)两类,本文将简要介绍埃式筛和欧式筛,并未对其中原理进行详细的介绍,若读者想了解两种筛选法的原理请查看算法学习笔记(1
阅读全文
摘要:一、摘要 二分算法是经常使用的算法之一,熟练使用二分算法是一个程序员的基本素养。C++的<algorithm>头文件中存在lower_bound()和upper_bound()函数,支持在已排好序的容器中查找首个大于等于或者大于目标元素的迭代器位置。同时在有序容器类,例如set<>和map<>,也存
阅读全文
摘要:一、摘要 这是我个人的树状数组模板记录,对于其他人可能没有借鉴意义。 二、代码 // 树状数组类 // 下标从1开始 class BinaryIndexedTree{ public: // 构造函数,初始化数据数组c_,大小为总数据个数+1 BinaryIndexedTree(int n){ c_.
阅读全文
摘要:前言 使用快速排序算法思想,查找数组中的第k大的数。复杂度为 O ( n ) O(n) O(n)。 代码 #include <iostream> #include <vector> #include <algorithm> // find median using namespace std; in
阅读全文
摘要:一、题意 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
阅读全文
摘要:转载自: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
阅读全文
摘要:一、题意 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
阅读全文
摘要:一、题目 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
阅读全文
摘要:本文参考博文判断一个数是不是质数(素数),3种方式介绍,原文章解释的已经很详细,本问增加部分博主自己的理解。 一、概念介绍 质数:质数是指在大于1的自然数中,除了1和它本身以外不再有其他因数的自然数。特别的0,1不是质数。 二、方法介绍 1.最直接的方法 bool isPrime(int n){ i
阅读全文
摘要:题目描述 Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.样例 Example 1:
阅读全文
摘要:题目 给定一个字符串 (s) 和一个字符模式 (p)。实现支持 '.' 和 '*' 的正则表达式匹配。 '.' 匹配任意单个字符。 '*' 匹配零个或多个前面的元素。 匹配应该覆盖整个字符串 (s) ,而不是部分字符串。 说明 s 可能为空,且只包含从 a-z 的小写字母。p 可能为空,且只包含从
阅读全文
摘要:#汉诺塔# 代码 #include <iostream> #include <stdio.h> using namespace std; //汉诺塔函数,参数,n剩余棋子数,prime棋子初始所在杆,help移动棋子需要借助的杆,target最终移动的目标杆 void hanoi(int n, ch
阅读全文
摘要:八皇后问题 代码 #include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <cmath> using namespace std; int p[8][8]; // 棋盘数组 int c
阅读全文