数据结构
文章平均质量分 60
Free_way
这个作者很懒,什么都没留下…
展开
-
树状数组 区间更新 区间求和
树状数组天生用来动态维护数组前缀和,其特点是每次更新一个元素的值,查询只能查数组的前缀和, 但这个题目求的是某一区间的数组和,而且要支持批量更新某一区间内元素的值,怎么办呢?实际上, 还是可以把问题转化为求数组的前缀和。 首先,看更新操作update(s, t, d)把区间A[s]...A[t]都增加d,我们引入一个数组delta[i],表示 A[i]...A[n]的转载 2014-02-14 22:30:08 · 1417 阅读 · 0 评论 -
HDU 2203 - 亲和串
可以让s1、s2互相进行KMP,看最后匹配的长度是否>= len2即可。举个例子: AABCD CDAA #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <algorithm> #include <ctype.h> #include <iostream> #include原创 2015-07-25 16:01:36 · 611 阅读 · 0 评论 -
HDU 数据结构 - 字典树 解题报告汇总
Virtual Judge 题目链接:打开链接HDU 1617 - Phone ListHDU 1251 - 统计难题HDU 1004 - Let the Balloon RiseHDU 1075 - What Are You Talking AboutHDU 4287 - Intelligent IMEHDU 1800 - Flying to the Mars HDU 1804 - Deli De原创 2015-07-25 14:57:23 · 1118 阅读 · 0 评论 -
[BestCoder] Round #25 1001 - Harry and Magical Computer | HDU 5154
题目给了中文描述,所以不再多说。 裸拓扑排序,直接用队列维护入度为零的结点,判断是否能完全删除M条边即可。 #include #include #include #include using namespace std; int main() { int cnt, n, m, a, b, v[1000]; while(~scanf("%d %d", &n, &m))原创 2015-01-03 23:23:58 · 919 阅读 · 0 评论 -
[字典树、map] HDU 1800 - Flying to the Mars
题意: 给定很多人的能力值,原创 2014-11-16 09:21:02 · 787 阅读 · 0 评论 -
[字典树 + dfs] HDU 1298 - T9
题目想了好久,发现需要在查询字典树的时候,枚举每个数字上的字母。就没敢去想用dfs。 但是后来经过计算发现,w最大值是1000,每个数字串长度最大为100。原创 2014-11-18 14:07:32 · 863 阅读 · 0 评论 -
[字典树] HDU 1247 - Hat’s Words
这个题一开始我想的是最暴力的方法,先把所有单词建成字典树。。 然后n^2复杂原创 2014-11-17 15:09:06 · 693 阅读 · 0 评论 -
[字典树] HDU 1804 - Deli Deli
字典树裸题,建树的时候,给每个节点加一个字符串原创 2014-11-17 11:06:12 · 852 阅读 · 0 评论 -
[字典树] HDU 4287 - Intelligent IME
题意: 给定每个数字对应的几个字母,然后rang原创 2014-11-16 00:23:18 · 930 阅读 · 0 评论 -
[字典树] HDU 1075 - What Are You Talking About
依旧字典树,题目读入有点难搞~~ #include #include #include #include using namespace std; char ch[3001]; struct Trie { Trie *ch[26]; char *cc; }; Trie *H; Trie *newnode() { Trie *p = new Trie; fo原创 2014-11-15 22:44:01 · 904 阅读 · 0 评论 -
[字典树] HDU 1004 - Let the Balloon Rise
可以用map做,附上字典树代码。 #include #include char max[100]; int ans; struct Trie { Trie * ch[26]; int sz; }; Trie p, *H; void init() { H = &p; for(int i = 0; i < 26; i++) { H->ch原创 2014-11-15 19:07:02 · 782 阅读 · 0 评论 -
[字典树] HDU 1617 - Phone List
之前用结构体排序做的,这次用字典树做一下~原创 2014-11-15 16:51:07 · 843 阅读 · 0 评论 -
[字典树] HDU 1251 - 统计难题
题目没给范围,动态建树做的~原创 2014-11-15 18:26:00 · 695 阅读 · 0 评论 -
[大话数据结构] 6.12.3 赫夫曼编码
今天抽时间看了一下赫夫曼编码,感觉挺有意思。那就做个小总结。原创 2014-06-06 19:09:16 · 1103 阅读 · 0 评论 -
[大话数据结构] 9.7 堆排序
#include #include using namespace std; int a[100]={0,2,1,3,6,5,4,9,7,8,0}, len = 10; void heapAdjust(int s, int l) { int temp = a[s]; for(int j = 2*s; j <= l; j *= 2) { if(j < l原创 2014-07-30 15:24:11 · 862 阅读 · 0 评论 -
[算法入门经典] 8.2 归并排序
#include int a[1000]={0,2,3,1,4,5,7,6,8,9,0}, b[1000]; //下标从1开始存储 void mergeSort(int x, int y) { if(y - x > 1) { int m = (x + y) / 2; mergeSort(x, m); mergeSort(m, y原创 2014-07-30 17:19:32 · 767 阅读 · 0 评论 -
二叉树已知前序遍历和中序遍历,编程求后序遍历。
在这个问题之前,我们应该知道前序遍历、中序遍历、后序遍历的定义。 前序遍历原创 2014-05-30 16:21:17 · 1578 阅读 · 0 评论 -
HDU 1277 - 全文检索
用字典树做的,要把输入的M行数据存到一个数组中即可。。 由于题目给出任何两个关键字的前4个数字是不同的,所以不会超时。#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <algorithm> #include <ctype.h> #include <iostream> #inc原创 2015-07-28 20:04:03 · 677 阅读 · 0 评论