自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(52)
  • 收藏
  • 关注

原创 hdu 1711

题目模版题目代码如下:#include#includeusing namespace std;const int maxn=1000005;int a[maxn],b[10005];int next[maxn];int n,m;void getNext(){ int i,j,k; next[1]=0; i=1;j=0; whil

2013-08-04 16:05:49 585

原创 poj 2481

题目与stars类似,不过此题找的是左上角的值,这样把e按照从大到小排序,s仍然是从小到大排序。剩下的注意离散化就行了。树状数组数以的是:一定不能从0开始,否则0+lowbit(0)=0,会陷入死循环所以需要++;代码如下:#include#include#include#includeusing namespace std;const int maxn=

2013-08-03 15:09:12 677

原创 poj 1195

题目一道二维树状数组的裸题。把更新,求和函数改成二维即可求和的时候注意要getsum(x2,y2)-getsum(x1-1,y2)-getsum(x2,y1-1)+getsum(x1-1,y1-1)画图即可理解。代码如下:#include#include#includeusing namespace std;const int maxn= 1050;i

2013-08-03 14:44:00 933 1

原创 poj 2155

题目二维树状数组。由于是翻转的操作,而且是区间操作,所以以往的update和query的操作是翻过来的。update(x1-1,y1-1),update(x2,y2),update(x1-1,y2),update(x2,y1-1).画出矩形区域来模拟一下很好理解。由于只是记录是0还是1,所以在getSum中只需要模2即可。可以用二维线段树写,代码多了很多。代码如下:

2013-08-02 23:25:35 605

原创 husj oj

F - InversionsTime Limit:500MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64uSubmit StatusDescriptionThere are N integers (1A[j].InputThe first line of the i

2013-08-02 17:30:40 926

原创 poj 3067

题目还是树状数组求逆序数先按e升序,若e相等时再按s升序,每次求出比b大的数字的个数,再更新即可代码如下:#include#include#include#includeusing namespace std;const int maxn=1005;int a[maxn];int n,m,k;struct Way{ int e,s;}way[ma

2013-08-02 16:16:19 632

原创 poj 2352

题目树状数组求逆序数按照题目输入的顺序,只需要找出(1,x)有几个点即可,然后更新。代码如下:#include#include#includeusing namespace std;const int maxn=32005;int a[maxn];int Lowbit(int x){ return x&(-x);}void update(int

2013-08-02 16:05:17 548

原创 poj 2299

树状数组求逆序数离散化之后,每次插入一个数,在该数字的位置上加上1,即update(c[i],1)接着getSum找到比他小的数的个数,最后用i减掉即为逆序数。在纸上模拟下这个过程就很容易理解。树状数组的基本功能之后就是需找比当前位置小或者大的数shuzhuagnshuzu

2013-07-31 01:43:50 562

原创 hdu 4217

题目区间内第k小数,求其和。代码如下:#include#includeusing namespace std;const int maxn= 262147;struct Tree{ int l,r; int sum;}tree[maxn<<2];inline void PushUp(int rt){ tree[rt].sum=tre

2013-07-30 11:09:28 773

原创 poj 2912

题目和那道食物链的题目差不多。公式的推导还是其他的情况感觉做这一类权值的并查集,Union函数中的通过已知的东西对于路径的更新很重要大部分和http://blog.csdn.net/hange_db/article/details/9529743#comments差不多膜拜荡神代码如下:#include#includeusing namespace std;#

2013-07-28 01:28:19 873 1

原创 poj 1456

题目为了获取利润最大,所以贪心把所有的商品按照利润排序。接着通过并查集将已买的物品的父节点往前更新知道t=0,即,已经到了最前端代码如下:#include#include#includeusing namespace std;const int maxn=10010;struct Item{ int pro,end;}item[maxn];

2013-07-27 15:41:59 541

原创 hdu 3038

题目和3047差不多。但是为什么是a--。不理解,不加这条就一直wa代码如下:#include#includeusing namespace std;const int maxn=200005;int pre[maxn],val[maxn];void init(int n){ for(int i=0;i<=n;i++){ pre[i

2013-07-27 09:39:02 733

原创 hdu 3172 && hdu 3047

题目并查集,大水题直接代码:#includeusing namespace std;#include#includeconst int maxn=100005;int pre[maxn],val[maxn];map m;inline int input(){ char c; int ret=0; c=getchar(); whi

2013-07-27 01:14:23 650

原创 hdu 1856

题目并查集。找到最大出现的那个点。对于每一个线段使得其权值加1最后统计根节点的权值最大的就是答案当n=0是,答案是1.特殊数据特判,否则wa另外并查集的查找操作,若按其他方式写的话,即超时。最后各种bug的加速情况下46msAC代码如下:#includeusing namespace std;#includeconst int maxn=100000

2013-07-27 00:18:09 566

原创 poj 2492 && poj 1703

poj 2492因为只有两种关系,所以val代码的与根节点的距离可以来模2对于根节点的更新,在题目的描述中加上自己的理解可以得出代码如下:#includeusing namespace std;#includeconst int maxn=100010;int pre[maxn],val[maxn];int find(int x){ if(pre[x]=

2013-07-26 15:35:57 591

原创 poj 1988 &&poj 2524

poj 1988num是统计该堆中cube的数目ans是统计该cube下面的cube的数目代码如下:

2013-07-25 08:55:51 534

原创 poj 1182

题目带权的并查集。在网上看了别人的详细解答后,才略微明白过来http://blog.csdn.net/c0de4fun/article/details/7318642代码如下:#includeusing namespace std;#includeconst int maxn=50005;int pre[maxn],rank[maxn];void init()

2013-07-24 16:53:10 525

原创 hdu 3635

题目wa了n次,最后网上搜代码。要先进行移动的步数的更新,在路径压缩,否则就是wa代码如下;#include#includeusing namespace std;#define maxn 10010int pre[maxn],num[maxn],times[maxn];inline int find(int x){ if(x==pre[x]) ret

2013-07-24 11:31:43 543

原创 poj 2777

题目用了二进制中1的个数来统计不同的颜色数最后在求解时用0来与这个数中的1或,统计颜色个数仍然是区间更新,区间询问代码如下:#include#includeusing namespace std;#define maxn 100010#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1struct Tree{

2013-07-24 10:07:50 520

原创 hdu 1823

题目二维的线段树。把身高区域看成x轴,活跃度看成是y轴,就找所交区域内值的最大值。把每一株线段树单独来看,很容易理解。代码中有详细解释,代码如下:#include#includeusing namespace std;#define maxn 2050struct sub_Tree{ int l,r; int val;};//子树str

2013-07-24 01:38:42 722 2

原创 LA 3644

X-Plosives A secret service developed a new kind of explosive that attain its volatile property only when a specific association of products occurs. Each product is a mix of two different simple c

2013-07-24 00:14:59 574

原创 poj 1308

题目有两点1、只有1个根,可以通过并查集来判断是否是同意祖先2、入度为0的点只有一个,其他的入度均为1通过这两点来判断,输入输出略坑的感觉代码如下:#include#includeusing namespace std;#define maxn 100000+10int pre[maxn],indegree[maxn],num[maxn];void Ini

2013-07-23 23:59:08 520

原创 hdu 3911

题目一直在用3397的现有代码去掉功能来代入这道题但是莫名的TLE了。于是按照网上大部分的方法,多维护了黑色的左,中,右连续1之和由于PushDown的时候忘记了把延迟标记传递下去,又贡献了几次WA最后在输入加速和inline的帮助下,成功600ms AC代码如下:#include#includeusing namespace std;#define maxn

2013-07-23 23:51:23 674

原创 poj 1611

题目多了一个需要维护的值,即为更新同一祖先的数。代码如下:#include#include#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;#define maxn 30010int pre[maxn];int num[maxn];int find(int x){

2013-07-22 15:59:31 541

原创 hdu 1272

题目判断是否有两个点的祖先已经是同一个了。判断是否联通。学了一句代码来防爆栈#include#include#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;#define maxn 100005int pre[maxn];bool flag,vis[maxn];i

2013-07-22 15:40:24 592

原创 hdu 1198

题目看了别人的思路,只需要对于上以及左来合并。最后遍历一遍就好,裸的并查集#includeusing namespace std;#define maxn 110int pre[maxn*maxn];char map[maxn][maxn];int find(int x){ return pre[x]==x?x:(pre[x]=find(pre[x]));}

2013-07-22 11:13:49 505

原创 hdu 1305

题目与1671差不多。不懂为什么加上了清空内存的函数,程序会死掉。注释掉就AC了代码如下:#include#includeusing namespace std;struct Trie{ int flag; Trie *next[2];};Trie *root;void buildTrie(char *str){ int len

2013-07-22 09:55:16 527

原创 hdu 1213

题目与上一题一模一样代码如下:#include#includeusing namespace std;int pre[1005];int find(int x){ int r=x; while(pre[r]!=r) r=pre[r]; return r;}void Union(int x,int y){ int fx=fin

2013-07-22 01:25:30 541

原创 hdu 1232

题目并查集水题,主要是熟悉三个函数代码如下:#includeusing namespace std;int pre[1005];int find(int x){ int r=x; while(pre[r]!=r) r=pre[r]; return r;}void Union(int x,int y){ int fx=find(x);

2013-07-22 01:17:01 518

原创 hdu 1075

题目字典树。代码如下:#include#include#include#includeusing namespace std;struct Trie{ char str[15]; Trie *next[26];}*root;void buildTrie(char *eng,char *mar){ int rt,i,len=strlen(m

2013-07-22 00:48:55 580

原创 hdu 1247

题目分成两段来判断,也是一道字典树的裸题#include#include#include#include#includeusing namespace std;typedef struct Trie{ bool v; Trie *next[26];}Trie;char s[50100][50],str1[100],str2[100];Trie *r

2013-07-21 16:04:08 533

原创 hdu 1671

题目数字的字典树。每一组数据结束一定要清空内存,不然会MLE#include#include#include#includeusing namespace std;struct Trie{ int flag; Trie *next[10];};Trie *root;void buildTrie(char *str){ int len

2013-07-21 10:37:21 564

原创 hdu 1251

题目根据字符串来建n叉树,就是字典树一般为26叉树,一般题目的关键在于建树时维护的其他值线段树时以线段作为一个一个的子节点,是二叉树。字典树即为n叉树。水题一枚,代码如下:#include#include#includeusing namespace std;struct Trie{ int flag; Trie *next[26];};

2013-07-21 10:19:44 558

原创 poj 3264

题目一个线段树的水题。用RMQ水了一个。时间比线段树快乐将近0.5s,但空间大了很多线段树代码如下:/* Memroy 2740K Time 4016Ms*/#include#includeusing namespace std;#define maxn 50005#define lson rt<<1#define rson rt<<1|

2013-07-21 09:21:16 594

原创 hdu 1806

题目区间合并。当update的时候注意所查询边界是与左右儿子的边界进行比较代码如下:#include#includeusing namespace std;#define maxn 100005#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1struct node{ int r,l; int mnum,ms

2013-07-21 09:16:29 747

原创 hdu 1542 &&poj 1151

题目用线段树来求矩形面积并比照着其他人的代码,总算理解了。先熟悉下,代码如下:#include#include#includeusing namespace std;#define maxn 220struct Node{ int l,r; int c; double len;}node[2000];struct Line{

2013-07-20 14:02:00 621 1

原创 hdu 1540 && poj 2892

题目D 指将改点更新为0Q 查询改点处左右两端的连续区间R 将前一个D的点回复成1#include#includeusing namespace std;#define maxn 50005#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1struct Tree{ int l,r; int lsum,

2013-07-18 13:24:38 590 1

原创 hdu 3397

题目0和1,分别将区间置0和置1,区间替换。2,区间翻转,只需要注意线段树中的sum、lsum、rsum、msum的值就好3,区间求和,得到几则有几个14,区间合并,注意在查询的时候合并。线段树综合好题,基本上所有的有关的操作都糅合进去了。奇迹般的1Y了!#include#includeusing namespace std;#define maxn 1000

2013-07-18 10:45:46 576

原创 poj 3667

题目根据题意来进行区间合并,和其他区间合并的题目差不多。关键是在线段树中要了解维护哪几个量,然后主要的操作在PushUp和PushDown两个函数中完成与其他类型的线段树的最大区别就在query中要有区间合并的过程。代码如下:#include#includeusing namespace std;#define maxn 50005#define lso

2013-07-17 16:52:09 620 1

原创 UESTC 1425

题目和hdu 3308差不多多了pushudown来更新区间内的值代码如下:#include#include#includeusing namespace std;#define maxn 100005#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1struct Tree{ int l,r; int

2013-07-16 16:17:26 578

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除