04 2013 档案

摘要:分析:2013!的六进制表示法尾部包含的0的个数意味着其因数分解中包含6的个数; 比如6!=6*5*4*3*2*1=(720)10进制=(3200)6进制,可见尾部包含2个0;深入分析:6=2*3,所以凡是因数分解中包含6的数一定能将6进一步分解为2和3,且2、3为质因数;所以,可以遍历1-2013的每个数N,求得所有N的质因数分解中包含的3的个数count,然后累加所有count即为最后结果。代码如下:int count_three(int N){ int count=0; while(N%3==0) { count++; N /= 3; ... 阅读全文
posted @ 2013-04-28 22:28 xiaowenchao 阅读(251) 评论(0) 推荐(0)
摘要:#include #include #include using namespace std;using namespace stdext;//acronym : LNSpair longest_norepeat_substring( string& str ){ hash_map char_index;//save the character and last postion it appears size_t currentStart = 0;//start position of the LNS size_t repeated_postion = 0;//the last pos 阅读全文
posted @ 2013-04-28 22:05 xiaowenchao 阅读(210) 评论(0) 推荐(0)
摘要:转载自http://blog.sina.com.cn/s/blog_4ce0162301013v81.html题目:给定一个包含40亿个随机排列的顺序文件,找到一个不在文件中的32位整数,在有足够内存的情况下应该如何解决该问题?如果有几个外部的临时文件可用,但是仅有几百字节的内存,又该如何解决?(1)对于有足够内存的情况,完全可以采用位图存储的方法,详细内容看《编程珠玑》第一章。(2)Ed Reingold 给出了另外一种解法。 问题的关键是只要找到一个数字,那么我们把问题简化一下,给定一个文件,里头最多包含16个4bit的整数,找到一个不在文件中的4bit整数。假设这十个数是1 2 3 4. 阅读全文
posted @ 2013-04-25 11:15 xiaowenchao 阅读(701) 评论(0) 推荐(0)
摘要:原书代码如下:#include <iostream>#include <math.h>#include <time.h>#define BITSPERWORD 32#define SHIFT 5#define MASK 0x1F#define M 100#define N 10000000int a[1+N/BITSPERWORD];void set(int i){ a[i>>SHIFT] |= (1<<(i & MASK));}void clr(int i){ a[i>>SHIFT] &= ~(1< 阅读全文
posted @ 2013-04-25 11:12 xiaowenchao 阅读(218) 评论(0) 推荐(0)