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

2012年10月13日

摘要: Trie树,是一种树形结构,是一种哈希树的变种。典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计。它的优点是:利用字符串的公共前缀来节约存储空间,最大限度地减少无谓的字符串比较,查询效率比哈希表高。字典树与字典很相似,当你要查一个单词是不是在字典树中,首先看单词的第一个字母是不是在字典的第一层,如果不在,说明字典树里没有该单词,如果在就在该 字母的孩子节点里找是不是有单词的第二个字母,没有说明没有该单词,有的话用同样的方法继续查找.字典树不仅可以用来储存字母,也可以储存数字等其它数 据。http://www.cnblogs.com/tank 阅读全文

posted @ 2012-10-13 15:12 皇星客栈--Linux 阅读(152) 评论(0) 推荐(0) 编辑

2012年10月11日

摘要: 求多字符串的最长公共子串(POW) 给定n个字符串,求这n个字符串的最长公共子串。例如给3个字符串:'abcb'、'bca'和'acbc',则这三个字符串的最长公共子串即为'bc'。输入第一行为n,下面n行即为这n个字符串。输出它们的最长公共子串。样例:输入:输出:3abcbbcaacbcbcView Code 1 #include<stdio.h> 2 #include<string.h> 3 4 char POW[200][200]; 5 char S[200]; 6 char T[200]; 7 in 阅读全文

posted @ 2012-10-11 21:35 皇星客栈--Linux 阅读(663) 评论(0) 推荐(0) 编辑

2012年10月7日

摘要: 给定主串S和模式串T,求T串在S串中所有出现的位置,允许不同位置的T串有部分重叠。例如:S='abababab',T='abab',T在S中出现的总次数就是3次(包括1、3、5三个起点位置,虽然S[1..4]与S[3..6]有部分重叠,但这是允许的)。输入信息包括两行,第一行为S串,第二行为T串;按从小到大的顺序输出所有T串出现的位置。样例:输入:输出:abababababab1 3 5View Code 1 #include<stdio.h> 2 #include<string.h> 3 4 void get_nextval(char 阅读全文

posted @ 2012-10-07 00:31 皇星客栈--Linux 阅读(639) 评论(0) 推荐(0) 编辑

2012年10月5日

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2087View Code 1 #include<stdio.h> 2 #include<string.h> 3 4 void get_nextval(char T[ ],int nextval[ ]) 5 {//求模式串T的next函数修正值并存入数组nextval. 6 int i=1,j=0; 7 int length; 8 nextval[1]=0; 9 length=strlen(T);10 11 while(i<length)12 ... 阅读全文

posted @ 2012-10-05 14:21 皇星客栈--Linux 阅读(212) 评论(0) 推荐(0) 编辑

摘要: View Code 1 #include<stdio.h> 2 #include<string.h> 3 4 void get_nextval(char T[ ],int nextval[ ]) 5 {//求模式串T的next函数修正值并存入数组nextval. 6 int i=1,j=0; 7 nextval[1]=0; 8 int length; 9 length=strlen(T);10 11 while(i<length)12 { 13 if(j==0||T[i]==T[j])14 ... 阅读全文

posted @ 2012-10-05 13:27 皇星客栈--Linux 阅读(367) 评论(0) 推荐(0) 编辑

2012年10月2日

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2054View Code 1 #include<stdio.h> 2 #include<string.h> 3 4 int isdec( const char *p ) 5 { 6 int i; 7 int len=strlen(p); 8 for( i=0 ; i<len ; i++ ) 9 {10 if( *p == '.' )11 return 1;12 p++;13 }14 return 0;1... 阅读全文

posted @ 2012-10-02 00:15 皇星客栈--Linux 阅读(163) 评论(0) 推荐(0) 编辑

2012年8月20日

摘要: G-WindProblem Description N棵树和M个蘑菇排成一排. 每棵树有自己的坐标和高度, 每个蘑菇有自己的坐标和权值. 一阵大风刮来, 每棵树有Li%的概率往左边倒, 有Ri%的概率往右边倒, 有(1 – Li% - Ri%)的概率不倒. 如果一棵高度为H坐标为X的树往左边倒下, 那么坐标在区间[X – H, X)内的蘑菇就会被砸到, 如果往右边倒下, 那么坐标在区间(X, X + H]内的蘑菇就会被砸到. 求不被树砸到的所有的蘑菇的权值之和的期望值。 Input 第一行包含2个整数N, M.接下来N行, 每行4个整数X, H, L, R. 表示这棵树的坐标, 高度和往左右倒 阅读全文

posted @ 2012-08-20 20:18 皇星客栈--Linux 阅读(175) 评论(0) 推荐(0) 编辑

2012年8月18日

摘要: A.ChessProblem DescriptionWe have a chessboard, as the figure below, it shows the chessboard with dimension 1, 3, 5, 7 (We ignore the even number).Now, your task is to place K bishops on the n – dimension chessboard and satisfied that none of then attack each other ( A bishop can move to any distan. 阅读全文

posted @ 2012-08-18 11:29 皇星客栈--Linux 阅读(257) 评论(0) 推荐(0) 编辑

2012年8月14日

摘要: 方法一:时间复杂度(n^2)我们依次遍历整个序列,每一次求出从第一个数到当前这个数的最长上升子序列,直至遍历到最 后一个数字为止,然后再取dp数组里最大的那个即为整个序列的最长上升子序列。我们用dp[i]来存放序列1-i的最长上升子序列的长度,那么 dp[i]=max(dp[j])+1,(j∈[1, i-1]); 显然dp[1]=1,我们从i=2开始遍历后面的元素即可。View Code 1 #include<stdio.h> 2 3 int dp[1000]; 4 int a[1000]; 5 6 int main( ) 7 { 8 int i; 9 int j;10 ... 阅读全文

posted @ 2012-08-14 14:58 皇星客栈--Linux 阅读(1463) 评论(0) 推荐(1) 编辑

2012年8月13日

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2191View Code 1 #include<cstdio> 2 #include<cstring> 3 4 int price[101]; 5 int weight[101]; 6 int num[101]; 7 int record[101]; 8 9 int main( )10 {11 int C;12 int n;13 int m; 14 int i;15 int j;16 int k;17 18 for( scanf("%... 阅读全文

posted @ 2012-08-13 15:59 皇星客栈--Linux 阅读(157) 评论(0) 推荐(0) 编辑