目录 C++ 的Lambda表达式 C++ 11 标准发布,各大编译器都开始支持里面的各种新特性,其中一项比较有意思的就是lambda表达式。 语法规则 C++ 11 Lam

今年准备安安心心写一个协程库。一方面是觉得协程挺有意思,另一方面也是因为C/C++在这方面没有一个非常权威的解决方案。 按照我自己风格还是喜欢

C++11标准里有动态模板参数已经是众所周知的事儿了。但是当时还有个主流编译器还不支持。 但是现在,主要的编译器。VC(Windows),GC

用过std和boost的function对象和bind函数的童鞋们都知道这玩意用起来腰不酸了,腿不疼了,心情也舒畅了。先上一个简单得示例: std::string

/** * 二维ACM计算几何模板 * 注意变量类型更改和EPS * #include <cmath> * #include <cstdio> * By OWenT */ const double eps = 1e-8; const double pi = std::acos(-1.0); //点 class point { public: double x, y; point(){}; point(double x, double y):x(x),y(y){}; static int xmult(const point &ps, const point &pe, const

/** * 简易四则运算(栈实现) * #include <stack> * #include <cstring> */ std::stack<char> opr; std::stack<double> num; char oprPRI[256]; //初始化调用 void initCalc() { //优先级设置 char oprMap[7][2] = { {'+', 1}, {'-', 1}, {'*', 2}, {'/', 2}, {'^', 3}, {'(', 100}, {')', 0} }; for(int i = 0; i < 7; i

基础函数: // 最大公约数,欧几里得定理 int gcd(int a, int b) { return b?gcd(b, a % b): a; } // 拓展欧几里得定理 // 求解ax + by = gcd(a,b) int ext_gcd(int a, int b, int &x, int &y) { int tmp, ret; if(!b) { x = 1; y = 0;

树状数组模块 ACM个人模板 POJ 2155 题目测试通过 /** * 树状数组模块 * 下标从0开始 */ typedef long DG_Ran; typedef long DG_Num; const DG_Num DG_MAXN = 1005; //2^n DG_Num LowBit(DG_Num n) { return n & (-n); } //获取父节点索引 DG_Num DGFather(DG_Num n)

/** * 线性筛法求素数表 * 复杂度: O(n) */ const long MAXP = 1000000; long prime[MAXP] = {0},num_prime = 0; int isNotPrime[MAXP] = {1, 1}; void GetPrime_Init()//初始化调用 { for(long i = 2 ; i < MAXP ; i ++) { if(!

/** * Hash模板 * Based: 0 * template<unsigned long _SZ,class _T, unsigned long *pFun(_T _Off)> * class _My_Hash_ToInt * 传入数据大小_SZ,传入类型_T,Hash函数 * 传入类型_T必须重载 = 和 == 符号 * 收录了ELF

//Prime连通路模块 #define N 1000 //最大数据规模 #define MAXNUM 3000000 //最大路径长度 typedef double PrimeType;//路径类型 PrimeType PrimeRecord[N]; PrimeType dis[N][N]; int isLined[N] = {1,0}; PrimeType GetPrimeLength(const long n) { PrimeType tmpLen = MAXNUM; long

//MULDATATYPE为矩阵元素类型,MAXMAT为最大矩阵大小 typedef long MULDATATYPE; #define MAXMAT 100 #define inf 1000000000 #define fabs(x) ((x)>0?(x):-(x)) #define zero(x) (fabs(x)<1e-10) struct mat { long n,m; MULDATATYPE data[MAXMAT][MAXMAT]; void operator =(const mat& a); mat operator +(const mat& a); mat operator -(const mat&

//n每个用例的点个数 //MAXN为最大点个数 //PTYPE为坐标值类型 #include<iostream> #include<cmath> using namespace std; #define MAXN 1005 #define EPS 1e-10 typedef double PTYPE; struct point { PTYPE x,y; }; struct node { PTYPE k; }; int cmp(const void * a, const void *

//并查集 //注意类型匹配 const int maxn = 100002; int DSet[maxn]; void init(int n) { for(int i = 0 ; i <= n ; i ++) DSet[i] = i; } int findP(int id) { if(DSet[id] != id) DSet[id] = findP(DSet[id]); return DSet[id]; } //返回根节点ID int UnionEle(int a,int b) { a = findP(a); b

/** * KMP模式匹配 * 算法复杂度O(m+n) * ACM 模板 * * @Author OWenT * @link http://www.owent.net */ // 最大字符串长度 const int maxLen = 10000; // 前一个匹配位置,多次匹配注意要重新初始化 // 注: