摘要: 题意给定一个由NC个字母组成的字符串,求长度为N的不同子串的个数思路:由于只有NC个字母,可以将字母编号,0 ~ NC - 1,转换成数字,就可以将字符串表示成NC进制的数字,这样所有字串代表的数字都是唯一的,转换成10进制的数也是唯一的!就像10的二进制表示只有1010例如3 4daababacd = 3a = 0b = 1c = 2daa = 3 * 4 ^ 2 + 0 * 4 ^ 1 + 0 * 4 ^ 0 = 48#include <stdio.h>#include <string.h>char str[1000000];bool hash[16000000] 阅读全文
posted @ 2011-04-19 16:50 L.. 阅读(669) 评论(0) 推荐(0) 编辑
摘要: 明显的优先队列用了STL,但是不全懂,自己写个堆估计悬... 有工具咱就用!#include <iostream>#include <queue>#include <vector>#include <stdio.h>using namespace std;const int MAXN = 60001;struct message{ char name[20]; int para,pri; int order; bool operator < (const message& m1)const { if(pri == m1.pri) r 阅读全文
posted @ 2011-04-19 16:23 L.. 阅读(433) 评论(0) 推荐(0) 编辑
摘要: 题意判断一组字符串中是否出现自己的前缀子串思路字典树#include <stdio.h>#include <string.h>const int MAXN = 100010;struct dicTree{ int next[10]; bool isWord; void init(){ memset(next,-1,sizeof(next)); isWord = false; }};dicTree tree[MAXN];int num; bool ok;void insert(char *s){ int index = 0 ,level = 1; while( *s ){ 阅读全文
posted @ 2011-04-19 16:14 L.. 阅读(239) 评论(0) 推荐(0) 编辑