上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 27 下一页
摘要: 该题可以用树状数组也可以用线段数;树状数组:#include<stdio.h>#include<stdlib.h>#include<string.h>int c[50024],sum[50024],N;int lowbit(int x){ return x&(-x); }int SUM(int n){ int sum=0; while(n){ sum=sum+c[n]; n-=lowbit(n); } return sum; }void add(int n,int num){ while(n<=N){ ... 阅读全文
posted @ 2012-02-15 19:56 wutaoKeen 阅读(282) 评论(0) 推荐(0) 编辑
摘要: [HNOI2002]营业额统计 一个丰富的OI题库 http://www.zybbs.org/JudgeOnline/ 这题其实很一道很裸的Splay_tree,每次插入一个节点,我们就把它旋转到根节点,然后把最靠近这个节点的两个值(左子树的最大值,右子树的最小值)找出来比较一下就行了,对于Splay_tree 我就不累叙了;#include<iostream>#include<cstdio>#include<string>#include<cstdlib>using namespace std;class Tree{ public: int n 阅读全文
posted @ 2012-01-11 20:46 wutaoKeen 阅读(783) 评论(0) 推荐(0) 编辑
摘要: 这是一道Splay_tree题。伸展树(SplayTree)是一种二叉排序树, 它能在O(logn)内完成插入、查找和删除操作。它由DanielSleator和RobertTarjan创造。它的优势在于不需要记录用于平衡树的冗余信息。在伸展树上的一般操作都基于伸展操作。查找树的相关知识 各种查找树存在不足。比如:对于一个有n个节点的平衡树,虽然最坏情况下每次查找的时间复杂度不会超过O(logn),但是如果访问模式不均匀,平衡树的效率就会受到影响。此外,它们还需要额外的空间来存储平衡信息。 这些查找树的设计目标都是减少最坏情况下单次操作时间,但是查找树的典型应用经常需要执行一系列的查找操作,.. 阅读全文
posted @ 2012-01-11 20:42 wutaoKeen 阅读(442) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<stdlib.h>#include<string.h>int main(){ char num[1024],s[1024],c[15]; int n; while(scanf("%d",&n),n) { scanf("%s",c); memset(num,0,sizeof(num)); int len=strlen(c); num[1]=c[0]; for(int i=1;i<len;i++){ int j=1; while( n... 阅读全文
posted @ 2012-01-09 17:40 wutaoKeen 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 这个题搞的我好纠结呀!一直是WA,后来才知道自己记录的时候搞错了,ans应该为-1而不是0,因为当时同一个点时,距离为0;这里要用到LCA,我们的距离为两个子节点到根的距离和减去最近祖先的距离的2倍;#include<cstdio>#include<iostream>#include<string.h>#include<vector>using namespace std;class node{public: int en; int len; };vector<node>tree[10024],Qes[10024];int dist[ 阅读全文
posted @ 2012-01-08 14:01 wutaoKeen 阅读(349) 评论(0) 推荐(0) 编辑
摘要: 该题一下子就爆栈了,我还只能用G++可以提交,c++还是过不了;该题是一道LCA,这里就不重复了,(前面已经说了);#include<cstdio>#include<iostream>#include<string.h>#include<vector>using namespace std;class node{public: int en; int len; };vector<node>tree[40024],Qes[40024];int dis[40024],ans[40024],set[40024],visit[40024],a 阅读全文
posted @ 2012-01-07 21:45 wutaoKeen 阅读(250) 评论(0) 推荐(0) 编辑
摘要: 这是一道找最近祖先的问题,我用的是纯暴力的方法。#include<iostream>#include<cstdio>using namespace std;int father[10024];int father1[10024];int father2[10024];int main(){ int n,T,f,s; scanf( "%d",&T ); while( T-- ) { scanf( "%d" ,&n ); for( int i=0;i<=n;i++ ) father[i]=i; for( int 阅读全文
posted @ 2012-01-07 09:47 wutaoKeen 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 该题的题意是给你一个数字字符串,要你在其中抽去n个数字所组成的数字最小。这个题可以从反方向出发,我们可以从中抽取字符串长度(len)减去n组成最小的数字;我们知道要想最小第一个数前面一定没有比他大,也就是我们可以从0-(len-n-1)里面找最小的,找到之后,再从找到第一个数的位置后一个找第二个,以此类推。再结合RMQ就可以了。#include<iostream>#include<cstdio>#include<cmath>#include<string>#include<string.h>using namespace std;in 阅读全文
posted @ 2012-01-06 21:15 wutaoKeen 阅读(346) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<cstdlib>#include<cmath>#include<cstdio>#include<string.h>using namespace std;int num[50024],dp_min[20][50024],dp_max[20][50024];inline int min( int a,int b ){ return a>b?b:a; }inline int max( int a,int b ){ return a>b?a:b; }void get_RMQ( 阅读全文
posted @ 2012-01-06 12:11 wutaoKeen 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 该题是一道RMQ+二分RMQ(RangeMinimum/MaximumQuery)问题是求区间最值问题。你当然可以写个O(n)的(怎么写都可以吧=_=),但是万一要询问最值1000000遍,估计你就要挂了。这时候你可以放心地写一个线段树(前提是不写错)O(logn)的复杂度应该不会挂。但是,这里有更牛的算法,就是ST算法,它可以做到O(nlogn)的预处理,O(1)!!!地回答每个询问。 来看一下ST算法是怎么实现的(以最大值为例): 首先是预处理,用一个DP解决。设a是要求区间最值的数列,f表示从第i个数起连续2^j个数中的最大值。例如数列3245681297,f[1,0]表示第1个数起.. 阅读全文
posted @ 2012-01-06 12:02 wutaoKeen 阅读(596) 评论(0) 推荐(0) 编辑
上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 27 下一页