随笔分类 -  树状数组

HDU&&Color the ball
摘要:N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?#include <cstdlib> #include <iostream> #include<algorithm> #include<cstdio> #include<string.h> #include<string> usin 阅读全文

posted @ 2011-09-13 18:36 Hibernate4 阅读(187) 评论(0) 推荐(0)

POJ2481让人无语
摘要:今天上午弄一上午poj2481poj的2481树状数组,不会,原本是树状数组的题明明自己的代码和别人的几乎一样可是我的就过不了让人无语啊,谁能救救我,主啊,sowhat,把代码贴出来以求神牛不吝赐教,,,,,,终于找到错误了,无语啊,从上午9点开始debug一直到刚刚啊:现在贴出代码纪念死去的的时间:#include<iostream> #include<cstdio> #include<algorithm> #include<string.h> using namespace std; struct node { int s; int e; i 阅读全文

posted @ 2011-08-18 11:22 Hibernate4 阅读(324) 评论(0) 推荐(0)

树状数组原来可以这样用
摘要:高手的指点Topcoder上面的教程下面是树状数组的三个常用函数://c++代码inline int lowbit(int x) { return x&(-x); } void updata(int x,int y) { while(x<=n)//n是数组元素个数 { a[x]+=y; x+=lowbit(x); } } int sum(int k)//求a[1]+a[2]+.......+a[k] { int res=0; while(k) { a[k]+=res; k-=lowbit(k); } return res; } 阅读全文

posted @ 2011-08-17 11:51 Hibernate4 阅读(124) 评论(0) 推荐(0)

导航