Shirlies
宁静专注认真的程序媛~
posts - 222,comments - 49,views - 71万

随笔分类 -  acm_数据结构

hdu 3336【Count the string】(KMP)
摘要:一道字符串匹配的题目,仅仅借此题练习一下KMP因为这道题目就是要求用从头开始的n个字符串去匹配原来的字符串,很明显与KMP中求next的过程很相似,所以只要把能够从头开始匹配一定个数的字符串的个数加起来就OK了(再此结果上还应该加上字符串的长度,因为每个从头开始的字符串本身也可以去匹配自己的),即将next中值不为-1和0的个数统计出来即可。用GCC编译的,时间用了46MS。 1 #include 2 #include 3 #define MAXLEN 200005 4 #define MOD 10007 5 6 int next[MAXLEN]; 7 char myChar[MAXLE... 阅读全文
posted @ 2013-09-26 23:28 Shirlies 阅读(329) 评论(0) 推荐(0) 编辑
hdu 1394【Minimum Inversion Number】
摘要:线段树假如考虑iValue[i],则要先将iValue[1]->iValue[i-1]放在线段树里面,计算每一段里面包含多少个已遍历值(iValue[1]->iValue[i-1]),然后查找iValue[i]+1->n的值有多少个,这样的话,就相当与在查找iValue[1]->iValue[i-1]有多少个值是在iValue[i]+1->n范围的。(这一题目也可以用树状数组做)代码如下: 1 #include <iostream> 2 3 using namespace std; 4 5 struct node 6 { 7 int low,high; 阅读全文
posted @ 2012-12-01 12:43 Shirlies 阅读(206) 评论(0) 推荐(0) 编辑
hdu 1264【Counting Squares】
摘要:一道线段树的题目,由于之前没怎么做过线段树的题目,这道题我觉得还是有点小难的首先将x坐标排序,然后找相邻的x坐标之间的最大y值和最小y值,这些矩形是要覆盖x,x+1坐标的,然后将yMax,yMin分散到线段树上,并用一个值标记哪些节点被分布了,最后查找一遍就可以了。代码如下: 1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 using namespace std; 5 6 int X_axle[20000]; 7 8 struct node 9 { 10 int xLow 阅读全文
posted @ 2012-11-29 14:24 Shirlies 阅读(333) 评论(0) 推荐(0) 编辑
hdu 1198
摘要:一看到这一题,我真没想到用并查集做,坑啊,看看别人的大致思路才知道用并查集可以做,唉,看来是自己太弱了~~~View Code 1 #include <cstdio> 2 #include <cstring> 3 4 int pipe[11][4]={{1,0,0,1},{1,1,0,0},{0,0,1,1}, 5 {0,1,1,0},{1,0,1,0},{0,1,0,1},{1,1,0,1},{1,0,1,1}, 6 {0,1,1,1},{1,1,1,0},{1,1,1,1}};//将每个都编号了,并且用上了边 7 int f[3000]; 8 int map[300 阅读全文
posted @ 2012-03-10 00:02 Shirlies 阅读(462) 评论(0) 推荐(0) 编辑
hdu 2473
摘要:这一题是与并查集删除节点有关的,我想不出来怎么做,看了别人的解题思路,也依葫芦画瓢写了份代码,代码就没有必要贴了,说说自己看了别人解题思路后自己的理解吧。这一题是要求我们删除集合中的数并另外占一个集合,大家的思路基本上都是:用虚拟节点做父节点(之前的并查集,我们都是用自己做自己的父节点),我们修改的也只是与一个数关联的父节点。说是这样说,但是方法要想出来还是要费一番周折的。提供两种链接代码http://www.cppblog.com/MiYu/archive/2010/08/26/124771.htmlhttp://www.cnblogs.com/fornever/archive/2011/1 阅读全文
posted @ 2012-03-09 15:15 Shirlies 阅读(664) 评论(0) 推荐(0) 编辑
hdu 3635
摘要:题意:起初球i是被放在i号城市的,在年代更迭,世事变迁的情况下,球被转移了,而且转移的时候,连带该城市的所有球都被移动了:T A B(A球所在的城市的所有球都被移动到了B球所在的城市),Q A(问:A球在那城市?A球所在城市有多少个球呢?A球被转移了多少次呢?)。这一题还是蛮有意思的,虽然第一次写的时候超时了,因为我没有利用好查找函数的递归性,在合并的时候用一个循环将本来可以在查找时就合并好的,又另外处理的。View Code 1 #include <cstdio> 2 #include <string> 3 #define MAX 10010 4 5 int rank 阅读全文
posted @ 2012-03-06 16:11 Shirlies 阅读(1386) 评论(1) 推荐(1) 编辑
hdu 1811
摘要:不知道怎么下手,真没有想到这一题就来拓扑排序,本来看到这一题是觉得要用拓扑的,可是这一题是属于并查集的,并且也不知道怎么用拓扑来处理,汗,搜搜,发现竟然还可以用队列来实现拓扑,精神!是参考以下代码的:http://972169909-qq-com.iteye.com/blog/1052820 阅读全文
posted @ 2012-03-05 22:12 Shirlies 阅读(593) 评论(0) 推荐(0) 编辑
hdu 1829
摘要:这一题是听同学讲过例题后,现在做起来,感觉特别有意思。rank表示当前点到父节点的距离,如果距离是奇数,那么这两个就是异性,否则是同性,所以可以用%2判定他们之间的性别。以下注释是根据自己的理解写的,其实也不太清楚自己的理解是否是正确的^_^View Code 1 #include "stdio.h" 2 #include "string.h" 3 4 int f[3000]; 5 int rank[3000]; 6 7 int find(int x) 8 { 9 int t;10 if(x==f[x])11 return x;12 13 t=fi... 阅读全文
posted @ 2012-03-05 11:13 Shirlies 阅读(1022) 评论(2) 推荐(1) 编辑
uva 297
摘要:#include "stdio.h"#include "stdlib.h"typedef struct nodes{char ch;struct nodes *child[4];}node;char s1[10000];int sum;int pos;node* newnode(){node* t=(node *)malloc(sizeof(node));if(t!=NULL){t->child[0]=t->child[1]=t->child[2]=t->child[3]=NULL;}return t;}void build(no 阅读全文
posted @ 2012-02-04 13:06 Shirlies 阅读(233) 评论(0) 推荐(0) 编辑
uva 712
摘要:晕,这一题我竟然修改了很长时间,汗,关键在自己对字符串处理好像还是不是很熟练#include "stdio.h"#include "math.h"int main(){int n;char ch;char c[300],target[10],re[1000];int count=1;int m,s,i,j;scanf("%d",&n);while(n){getchar();//注意啊!while((ch=getchar())!='\n');fgets(c,sizeof(c),stdin);scanf(" 阅读全文
posted @ 2012-02-03 18:15 Shirlies 阅读(205) 评论(0) 推荐(0) 编辑
uva 548
摘要:二叉树的基本题型,不过对于我来说还是有点考验的……#include "stdio.h"int inorder[10005];int postorder[10005];int sum;int min1,min2;int find(int a,int *p,int n){int i;for(i=n-1;i>=0;i--)if(p[i]==a)return i;return 0;}void tree_min_node(int n,int *d1,int *d2,int sum){int k;if(n<=0) return;k=find(d1[n-1],d2,n);su 阅读全文
posted @ 2012-02-03 12:05 Shirlies 阅读(655) 评论(0) 推荐(0) 编辑
uva 112
摘要:应该是第一次搞二叉树的题目,这一题貌似难度有点大啊,有人的代码写的很简洁易懂,VERY GOOD!也是初次接触cin.clear(),挺有意思的。我个人认为这位解释的比较好http://zhidao.baidu.com/question/252322814.html?fr=qrl&cid=866&index=3还有就是那个好的代码了http://www.sunnybtoc.com/page/M0/S625/625828.html 阅读全文
posted @ 2012-02-02 20:59 Shirlies 阅读(390) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示