lzhenf

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2012年3月23日

摘要: 布局new和普通New不同,相当于建立一个小堆空间 。#include <iostream>#include <string>#include <new>using namespace std;const int BUF = 512;class testing{private : string word; int len;public: testing(const string & s = "tesing",int n = 0 ) { word = s; len = n; cout <<word <<&qu 阅读全文
posted @ 2012-03-23 22:15 lzhenf 阅读(270) 评论(0) 推荐(0) 编辑

2012年3月21日

摘要: 用bitmap方法,内存只需要 512M左右#include <stdio.h>#include <memory.h>#define BYTESIZE 8long long bufferlen =500000000;char *pBuffer = new char[bufferlen]; void setbit(char * p , int posi){ for ( int i = 0 ; i < posi / BYTESIZE ; i++) { p++; } *p = *p | (0x01 << (posi % BYTESIZE)) ;}int ma 阅读全文
posted @ 2012-03-21 23:54 lzhenf 阅读(611) 评论(0) 推荐(1) 编辑

摘要: 某天有1千万条查询,大部分为重复的,可能只有300万条查询,每条查询的长度为1-255字节,请设计算法查找出最热门的10条查询哈希 + 最小堆 时间复杂度为O(nlgk) n为数据量 , k为查询长度,这里为10;#include <stdio.h>#include <cstring>#include <algorithm>using namespace std;#define HASHLEN 2807303#define CHARLEN 30typedef struct node_no_space* ptr_no_space;typedef struct 阅读全文
posted @ 2012-03-21 21:09 lzhenf 阅读(2016) 评论(0) 推荐(0) 编辑

2012年3月20日

摘要: #include <stdio.h>#include <algorithm>#include <memory.h>using namespace std;int result[1001][101];int w[101],v[101];int main(){ int totalTime , count; memset(result , 0 ,sizeof(result)); scanf("%d %d" , &totalTime , &count); for ( int i = 1 ;i <= count ; i++) 阅读全文
posted @ 2012-03-20 00:05 lzhenf 阅读(344) 评论(0) 推荐(0) 编辑

2012年3月19日

摘要: #include <stdio.h>typedef struct node{ int val; node* next;};node* reverse(node* list , node* &head){ if ( !list || !list->next ) { head->next = NULL; head = list; return list; } else { node* temp = reverse( list->next , head); temp->next = list; return list; }}node* nonreverse 阅读全文
posted @ 2012-03-19 23:22 lzhenf 阅读(3684) 评论(0) 推荐(0) 编辑

摘要: int checkCPU( ){ { union w { int a; char b; } c; c.a = 1; return(c.b ==1);} } 阅读全文
posted @ 2012-03-19 22:05 lzhenf 阅读(257) 评论(0) 推荐(0) 编辑

2012年3月6日

摘要: 主要包括4个文件,util.py文件主要负责截取每个块。rules.py文件定义两个类,超类Rule和分别对应的子类,子类定义了不同的划分块的要求,子类包换action函数,调用handler处理handlers.py定义了处理类,超类定义了方法,子类通过名字调用markup.py定义了超类parser,定义了子类basicTextParser,超类主要负责创造过滤器,添加规则,对每个块执行处理。#handler.py# -*- coding: cp936 -*-class Handler: """ 处理从parser调用的方法对象 这个解析器会在每个块的开始部分 阅读全文
posted @ 2012-03-06 15:47 lzhenf 阅读(2374) 评论(0) 推荐(0) 编辑

摘要: 【转自:http://www.ibm.com/developerworks/cn/linux/sdk/python/python-5/index.html#N1004E】我们谈到“文本处理”时,我们通常是指处理的内容。Python 将文本文件的内容读入可以操作的字符串变量非常容易。文件对象提供了三个“读”方法: .read()、.readline() 和 .readlines()。每种方法可以接受一个变量以限制每次读取的数据量,但它们通常不使用变量。 .read() 每次读取整个文件,它通常用于将文件内容放到一个字符串变量中。然而 .read() 生成文件内容最直接的字符串表示,但对于连续的面 阅读全文
posted @ 2012-03-06 15:34 lzhenf 阅读(694) 评论(0) 推荐(0) 编辑

2011年12月28日

摘要: 第五章 代理类 :为了实现容器或数组的多态性。 1 #include <iostream> 2 3 using namespace std; 4 5 class Vehicle 6 { 7 public: 8 virtual void start() const = 0 ; 9 virtual Vehicle* copy() const = 0 ;10 virtual ~Vehicle() {};11 };12 13 14 class AutoVehicle : public Vehicle 15 {16 public:17 void start() con... 阅读全文
posted @ 2011-12-28 00:36 lzhenf 阅读(248) 评论(0) 推荐(0) 编辑

2011年12月27日

摘要: 1 #include <iostream> 2 #include <map> 3 #include <vector> 4 #include <string> 5 #include <queue> 6 using namespace std; 7 const int MaxNum = 203; 8 const int MAX = 999999; //定义一个较大的数 , 用于松弛处理 9 //定义距离数组10 int dis[MaxNum];11 int n ; //节点的数目 : n+ 1 12 typedef pair<int 阅读全文
posted @ 2011-12-27 23:32 lzhenf 阅读(283) 评论(0) 推荐(0) 编辑