
数据结构
文章平均质量分 57
lj_acm
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
poj 2352
线段树,顺序存储实现 #include #include const int maxx=32000; const int maxn=15000; int l[3*(maxx+1)],h[3*(maxx+1)],w[3*(maxx+1)]; int N; int ans[maxn]; void Create(int t,int s,int f) { l[t]=s;h[t]=f; if(s<原创 2012-09-29 14:22:02 · 463 阅读 · 0 评论 -
poj 2442
多路归并+优先队列的使用 #include #include #include #include using namespace std; const int maxn=2000+10; int a[110][maxn],b[maxn],n,m; struct item { int s,b; item(int s,int b):s(s),b(b) { } }; bool原创 2013-05-01 17:31:27 · 754 阅读 · 0 评论 -
poj 3630
trie的简单应用 #include #include #include using namespace std; const int maxn=10000*10+10; int trie[maxn][11]; int val[maxn],tot; char str[10000+10][15]; int Insert(char *s) { int len=strlen(s);原创 2013-04-17 17:19:14 · 754 阅读 · 0 评论 -
uva 1423 LA 4255
这道题目思维+基础,好题目 拓扑排序 以后看到sij就要想到连续和转化为前缀和之差的思想,通过表格得到两两前缀和的大小关系,然后通过拓扑排序得到前缀和的大小序列,确定每个前缀和的大小,最后得到结果 #include #include #include using namespace std; const int maxn=11; int e[maxn][maxn],b[maxn],in原创 2013-03-01 17:46:18 · 569 阅读 · 0 评论 -
poj 2001
trie树水题 #include using namespace std; typedef struct node { char data; int count; node * next[26]; node * parent; node() { count=0; memset(next,0,sizeof(next)); } }trie; trie * r; void in原创 2012-10-20 16:27:28 · 477 阅读 · 0 评论 -
poj 2182
#include using namespace std; const int maxn=8000+10; struct node { int l,r,len; }tree[maxn*3]; void Create(int p,int l,int r) { tree[p].l=l; tree[p].r=r; tree[p].len=r-l+1; if(l!=r) { int mi原创 2012-10-18 23:25:02 · 480 阅读 · 0 评论 -
poj 2051
优先队列或者说是堆得应用,最暴力的想法就是没输出一个最小值,更新,然后再排序,若用快排,时间效率为O(knlgn),但不需要对所有的排次序,所以就用到最小堆 #include #include #include using namespace std; typedef struct node { int n,p,r; }ar; bool operator<(ar a,ar b) { i原创 2012-10-18 23:42:04 · 528 阅读 · 0 评论 -
poj 1200
裸哈希,感觉oj的数据弱啊,如果N很大的话,内存就不够用,可能我没想明白? #include #include const int maxn=16000010; char s[maxn]; int li[300]; short hash[maxn]; int tot; int main() { int N,NC; scanf("%d%d",&N,&NC);原创 2012-10-14 21:04:11 · 538 阅读 · 0 评论 -
POJ 1161
第一道并查集,47ms ,还是很慢啊,不过是绞尽脑汁,调试了n次,做出来的,思路还是挺清晰地 #include using namespace std; const int maxn=30010; int parent[maxn]; int amount[maxn]; int rank[maxn]; int n,m; void init() { for(int i=0;i<n;i++)原创 2012-09-23 20:16:13 · 558 阅读 · 0 评论 -
poj 1330
此题用的是并查集的思路,时间很慢,应该有更好的思路,但以目前的知识只能做成这样 #include using namespace std; const int maxn=10001; struct UFSTree { int data; int parent; int rank; }t[maxn]; int N; void init() { int i; for(i=0;i<N;i原创 2012-10-14 16:03:14 · 469 阅读 · 0 评论 -
poj 1195
树状数组,因为此是求二维数组的区间的和,所以将其扩展为二维树状数组 #include #include const int maxn=1100; int c[maxn][maxn]; int n; int LowBit(int x) { return x&(x^(x-1)); } void Update(int x,int y,int a) { for(int i=原创 2012-10-14 15:59:50 · 474 阅读 · 0 评论 -
poj 2524
并查集水题 #include using namespace std; const int maxn=50010; int tot,m,n; struct node { int rank; int data; int parent; }t[maxn]; void init() { for(int i=1;i<=n;i++) { t[i].data=i; t[i].rank=1原创 2012-10-15 09:12:42 · 636 阅读 · 0 评论 -
poj 2513
欧拉回路+并查集(判断图的联通)+Tire树(快速查找字符串,并且记录相应点的度数) Tire树相关知识http://zh.wikipedia.org/wiki/Trie #include using namespace std; const int maxc = 26; const int maxn = 500001; struct TrieNode { int key; TrieNo原创 2012-10-12 19:47:40 · 524 阅读 · 0 评论 -
poj 1308
注意的情况比较多,尤其是空树这一种 #include #include using namespace std; const int maxn=100; struct node { int s,f; node* next; };//在此数据结构采用链表,方便后续遍历算法 int indexNode[maxn];//用于构造索引的数组 int v[maxn]; node *head; in原创 2012-09-18 19:00:15 · 618 阅读 · 0 评论 -
poj 1577
题不难,数据结构之BST,就是输入纠结了一会 #include #include using namespace std; const int maxn=30; struct Tnode { char data; Tnode * lchild; Tnode * rchild; }; Tnode * root; void insert(Tnode * p,char c) { if原创 2012-10-09 23:17:44 · 593 阅读 · 0 评论 -
POJ 2106
知识点:栈的应用语法经验,主函数外的函数中的指针变量不能付给主函数中的指针,因为函数调用完后就会释放内存,赋值相当于没赋#include using namespace std; const int maxn=110; void trans(char *exp,char *atexp); int oc( char *s); int main() { int t=1,jud; c原创 2012-09-15 20:50:11 · 885 阅读 · 0 评论 -
hdu 4547
LCA模板题,用的方法是转化为RMQ问题来求解,各种WA,折腾了一整天,哎~~~ 1 #include 2 #include 3 #include string> 4 #include 5 #include 6 #include 7 using namespace std; 8 const in原创 2013-08-06 17:34:36 · 819 阅读 · 0 评论