- 博客(19)
- 资源 (1)
- 收藏
- 关注
原创 预编译
#line lineno #line lineno “filename”int main(){#line 777 "i'm here.cpp"assert("love" == "don't love");return 0;} 改变了当前预处理器的当前行和文件名称。对应着两个宏__FILE__和__LINE__。 #error error_messag
2015-04-23 10:26:29
450
转载 branch prediction
在stackoverflow看到的一篇文章http://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-an-unsorted-array 排序后竟然比不排序的速度更快,排序后快了几乎两倍的时间。很惊奇#include #include #include i
2015-04-21 11:26:37
562
原创 字符串中 区分中文字符还是英文字符
英文字符ASCII是在0到127之间的,而汉字的两个字节的ascii值都不在这个区间。int main(){ char s[] ="asfdfasf今天天气jfdsf可真热"; for (int i = 0; i < strlen(s); i++) if (s[i] > 0) std::cout<<s[i];//<<std::ends; else i++; ret
2015-04-17 11:02:03
1755
原创 将一个数的二进制位进行翻转
在学习redis源码的时候,看到了这段代码。很少写blog,不太会表达自己的观点。static unsigned long rev(unsigned long v) { unsigned long s = 8 * sizeof(v); // bit size; must be power of 2 unsigned long mask = ~0; while (
2014-12-28 09:38:39
859
原创 文件空间管理
文件中的空间是以gdbm_file_header.block_size进行分配的,如果有一些小的文件空间,则用多个avail_elem进行管理。typedef struct { int av_size; /*大小*/ off_t av_adr; /*文件中的偏移量*/ }avail_elem; ty
2014-12-06 10:44:25
579
原创 树状数组
树状数组一维树状数组 假设c[] 为树状数组,a[]为原数组,它们的关系是,c[i]代表从a[i]开始往前2^k个元素的和。(k为i转化成二进制后尾部包含0的个数)。数组的下标从1开始。即 c[1] =a[1]; c[2] = a[1] +a[2]; c[3] = a[3]; c[4] = a[1] +a[2] + a[3] + a[4]
2014-12-04 10:56:12
567
原创 Getting Started
/usr/include you need headerfiles. For c these are always located in /usr/include and subdirectories andsubdirectories thereofgcc -I/home/chenpenghello.c direct the compiler to look in the dire
2014-11-15 22:58:14
494
原创 apache内存管理1
如果由操作系统进行管理内存,操作系统在分配和管理内存,应该会存在用户态与核心态的切换,而且会有地址空间的预定和调拨物理存储器等一系列的操作,而这些操作是不可控的,极大的影响了效率。apache自己管理内存,速度是一个重要的原因。 每一连续的内存(逻辑上,物理上的地址空间不一定是)都由内存管理结点,管理着这段内存。内存表示方法是通过下标的进行表示的,如果下标为0,内存大小为(MIN_ALLO
2014-11-06 09:24:44
771
原创 C专家编程整理
符号就是程序中的一个基本信息单元。而组成符号的字符序列就不同,同一组字符序列在某个上下文环境中属于一个符号,而在另一个上下文中可能完全属于另一个符号。 编译器中负责将程序分解为一个一个符号的部分,一般称为“记法分析器”。 =不同于==,可能会因为漏打多打而出现错误。在写==习惯性写成如:if (3 == a),会减少出错。 词法分析中的“贪心法”,如果(编译器的)输入流截止
2014-11-05 16:30:42
656
原创 茁壮网络C语言开发笔试
1,char *ptr = (char *)malloc(20);int len = 0,len2 = 0; if (ptr) { strcpy(ptr,"abcdef"); len = strlen(ptr); memcpy(ptr,"abcdefg",7); len2 = strlen(ptr);
2014-10-11 23:51:32
1247
2
原创 其数排序(原地排序)
#include #include #include #include "memory.h"#include #include #include #include #include #include #include #include using namespace std;void SortBaseNum_InPlace(int a[],int n,int maxN
2014-08-20 00:10:14
643
原创 基数排序
#include #include #include #include "memory.h"#include #include #include #include #include #include #include #include using namespace std;#define N 10void SortBaseNumber(int a[]){
2014-08-19 22:06:48
441
原创 C++ Data 内存布局
class X{};class Y:virtual public X{};class Z:virtual public X{};class B:virtual public X{};class A:public Y,public Z,public B{}; class M{}; class N:virtual public X,virtual public M{
2014-08-18 23:32:23
1645
转载 网络最大流
1,一般增广路算法 采取标号法每次在容量网络中寻找一条增广路进行增广, 直至不存在增广路为止。增广路方法 2,最短增广路算法 每个阶段:在层次网络中,不断用BFS算法进行增广直到
2014-07-26 16:06:18
469
原创 C++ 四种强制类型转换
const_cast 将转换掉表达式的const性质。只有使用const_cast才能将const性质转换掉。 除了添加或删除const特性,用const_cast符来执行其他任何类型,都会引起 编译错误。static_cast 可以转换编译隐式转换的任何类型转换。
2014-07-26 16:04:07
517
原创 poj 1528 Perfection(素数分解)
因式分解 n= p1^e1*p2^e2...*pt^et.p1,..pt都是素数.则所有约数和(包括本身)为(1+p1+p1^2+..+p1^e1)*(1+p2+p2^2+...+p2^e2)*...*(1+pt+pt^2+... +pt^et)
2014-07-25 20:56:41
488
原创 poj 2992 Divisors
#include #include #include "memory.h"#include #include "stdio.h"using namespace std;#define N 435bool used[N];int p[N]; // p[0] 表示素数的个数int fac[N][90]; //fac[i][j] 1 到 i 的 过程中因子 为j的个数void
2014-07-25 19:31:08
479
原创 poj 2689 线性时间筛选素数
#include #include #include "stdio.h"#include "memory.h"#include using namespace std;#define N 50010bool used[1000010];int p[N];int cnt = 0;void Init(){ memset(us
2014-07-25 17:29:02
523
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人