随笔分类 -  数据结构

摘要:昨天学习了线段树的延迟标记;发现自己还有区间合并没有学;抓紧时间学习一下;代码: 1 #include 2 #include 3 #define maxn 200005 4 using namespace std; 5 6 struct tree 7 { 8 int l,r,msum,lsum,rsum,flag; 9 tree *right,*left; 10 }tr[maxn]; 11 int nonocount; 12 13 void build(tree *root,int l,int r) 14 { 15 root->l=l,root->... 阅读全文
posted @ 2013-10-17 11:55 Yours1103 阅读(124) 评论(0) 推荐(0)
摘要:A:超级大水题;代码: 1 #include 2 #define maxn 105 3 using namespace std; 4 int n,a[maxn],x,y,ans; 5 int main() 6 { 7 scanf("%d",&n); 8 for(int i=1; i=x&&a[i]=x&&(ans-a[i])n)printf("0");23 return 0;24 }View Code B:因为每次跳舞最多只有一个人以前跳过,所以很简单; 1 #include 2 #define maxn 1000 阅读全文
posted @ 2013-10-16 00:54 Yours1103 阅读(417) 评论(0) 推荐(0)
摘要:字符串处理的题目;学习了一下string类的一些用法;这个代码花的时间很长,其实可以更加优化;代码: 1 #include 2 #include 3 using namespace std; 4 string dict[114]= {"he","h","li","be","b","c","n","o","f","ne" 5 ,"na","mg"," 阅读全文
posted @ 2013-10-03 19:18 Yours1103 阅读(323) 评论(0) 推荐(0)
摘要:题目不难,感觉像是一个拓扑排序,要用双端队列来维护;要注意细节,不然WA到死 = =! 1 #include 2 #include 3 #include 4 #define maxn 100005 5 using namespace std; 6 7 int q[2*maxn],count[2][maxn],tail,head,n,m,in[maxn]; 8 vectorve[maxn]; 9 10 int solve(int lab)11 {12 head=tail=n;13 int cnt=0,cc=0,f=lab;14 for(int i=1;i<=n;i++)... 阅读全文
posted @ 2013-10-03 18:01 Yours1103 阅读(255) 评论(0) 推荐(0)
摘要:一道字典树异或的题,但是数据比较水,被大家用暴力给干掉了!以前写过一个类似的题,叫做the longest xor in tree;两个差不多吧!好久没写字典树了,复习一下!代码: 1 #include 2 #include 3 #include 4 #define maxn 100010 5 using namespace std; 6 int n,v[maxn],node,next[maxn][2],end[maxn]; 7 8 void add(int cur,int k) 9 {10 memset(next[node],0,sizeof(next[node]));11 ... 阅读全文
posted @ 2013-10-02 22:52 Yours1103 阅读(192) 评论(0) 推荐(0)
摘要:一个KMP的简单题不过好久没用过这个东东了,今天写的时候花了很多时间;只需要花点时间判断下所有的元素都相同的的情况就行了! 1 #include 2 #include 3 #include 4 #define maxn 1000006 5 using namespace std; 6 char s[maxn]; 7 int next[maxn]; 8 9 void getnext(char *t)10 {11 // t为模式串12 int i=0,j= -1,l = strlen(t);13 next[0] = -1;14 while(i < l)15 ... 阅读全文
posted @ 2013-09-28 21:29 Yours1103 阅读(251) 评论(0) 推荐(0)
摘要:这题也是一个线段树的水题;不过开始题目没看明白,害得我敲了一个好复杂的程序。蛋疼啊。。。。最后十几分钟的时候突然领悟到了题意,但是还是漏掉一个细节,老是过不去。。。以后比赛的时候不喝啤酒了,再也不喝了。。。。贴上代码: 1 #include 2 #include 3 #define maxn 262200 4 using namespace std; 5 6 struct tree 7 { 8 int num; 9 int l,r;10 tree *left,*right;11 } tr[maxn];12 int nodecount=0,a;13 14 void up... 阅读全文
posted @ 2013-08-27 09:46 Yours1103 阅读(153) 评论(0) 推荐(0)