树状数组(BIT)
diannaok
这个作者很懒,什么都没留下…
展开
-
HDU 1394 - Minimum Inversion Number
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1394 树状数组,一开始想搓了,没有想到: 当队头的数放到队尾时,队列中所有数的逆序数都有可能发生改变。。。 于是在扣除逆序数的时候,忘记减去新出现的逆序数! #include#include#include#define l原创 2012-07-28 13:32:03 · 463 阅读 · 0 评论 -
POJ 3270 / HDU 2838 - Cow Sorting
题目地址: http://poj.org/problem?id=3270 注意到了其中一部分需要__int64,另一部分被想当然的忽略了(以为不可能爆int)。结果WA了n久不知原因。 很经典的求逆序数题目。初学题。比基本的逆序数多了一个状态。即需要多写一个Query。 #include#includeusing namesp原创 2012-07-27 20:46:03 · 505 阅读 · 0 评论 -
HDU 4358 - Boring counting
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4358 2012年多校,6场,1009。 方法: 离散化 + 树状数组 + 离线处理 电科牛出的风骚题目,膜拜膜拜。。。 理解了N久。。。 树状数组用到了区间更新,单点询问。。。 问区间内,有多少个出现了K次的数,这个用树状数组去做。。。 具体上电科牛原创 2012-08-15 19:10:42 · 1217 阅读 · 1 评论 -
POJ 3067 - Japan
题目地址: http://poj.org/problem?id=3067 典型的树状数组题目。 跟小学时做的连线题很像,问共有多少个交点。两点间只能用线段连,并且假设不会有3条及以上的线段交于同一点。 假设两个点 (x1,y1)、(x2,y2) 假若 y2 > y1 ,那么此时,只要存在 x1 即其中一点在另一点的左上角。 所以原创 2012-07-27 20:39:50 · 331 阅读 · 0 评论 -
POJ 2155 - Matrix
题目地址: http://poj.org/problem?id=2155 二维树状数组入门题,没什么好说的,理解二维之后,其实跟一维差不多了。 区间更新,单点查询。 #include#includeusing namespace std;int n,m;int tree[1001][1001];void update(int x,int y原创 2012-09-05 12:14:01 · 351 阅读 · 0 评论 -
HDU 4267 - A Simple Problem with Integers
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4267 树状数组。 2012长春网赛。。。 46分左右1Y。。 一开始被小胖误导去敲线段树,后来发现用线段树敲,空间需求太大,并且操作麻烦。。。 重新写了个树状数组,花了十多分钟。 区间更新、单点查询。。。 其实只要能想到方法,敲起来很容易~。。。原创 2012-09-09 01:36:55 · 1952 阅读 · 0 评论 -
HDU 4268 - Alice and Bob
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4268 贪心 + 树状数组 贪心是怪叔叔想到的,然后让我敲~~ = = 一开始敲搓了,搓B不解释了~~ 贪心的想法很简单: 首先:A和B混合排序,先按照L排,L相等的按照W排,W相等的B排A前面。 然后,从头原创 2012-09-09 01:57:39 · 592 阅读 · 0 评论 -
POJ 2886 - Who Gets the Most Candies?
题目地址: http://poj.org/problem?id=2886 一开始翻译搓了。。。 囧。。。 F(p) is the number of positive integers that perfectly divide p. 这句话是求p的因子个数。。。。 那么首先,需要把所有数的因子个数预处理。。。原创 2012-07-27 21:21:03 · 510 阅读 · 0 评论 -
HDU 1166 - 敌兵布阵
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1166 树状数组 练手水题,单点更新,区间求和。 #include#includeusing namespace std;int n;int s[51000];void add(int i,int val){ while(i<=n){ s原创 2012-07-27 20:24:42 · 296 阅读 · 0 评论 -
HDU 1556 - Color the ball
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1556 树状数组练手。 区间更新,单点查询。 #include#includeint tree[110000];int n;void update(int v,int val){ while(v>0){ tree[v]+=val; v-=v&-v原创 2012-08-19 09:23:59 · 587 阅读 · 0 评论 -
SWUN 1012 - Card
Card 时间限制(普通/Java) : 5000 MS/ 10000 MS 运行内存限制 : 65536 KByte总提交 : 169 测试通过 : 32 描述 YCC有一堆卡片,每张卡片上都写着一个正整数。YCC很喜欢将这些卡片排成一排,然后任意计算其中一段连续的卡片上数字的总和。随着年龄的增长,YCC觉得这个有点太容易了,于是他原创 2012-07-27 15:41:04 · 584 阅读 · 0 评论 -
HDU 4339 - Query
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4339 12年多校 1009题。 方法: 树状数组+二分。 时间: O( n * logn * logn ) #include#include#includeusing namespace std;char str[2][1001000];原创 2012-08-02 21:30:10 · 464 阅读 · 0 评论 -
SWUN 1440 - 你的工资是多少
你的工资是多少 时间限制(普通/Java) : 2000 MS/ 6000 MS 运行内存限制 : 65536 KByte总提交 : 9 测试通过 : 3 描述 民大ACM团队毕业的成员,聚到一起开了一家IT公司。营业期间,公司的利润也是时而涨时儿跌,大家不得不感叹创业之艰辛。 当然,作为ACMer出身,公司对工资原创 2012-09-05 13:38:43 · 946 阅读 · 0 评论 -
POJ 3378 / UESTC 1460 - Crazy Thairs
UESTC 地址 : http://acm.uestc.edu.cn/problem.php?pid=1460POJ 地址 : http://poj.org/problem?id=3378 经典题目。 方法 :树状数组+dp+离散化+大整数 时间复杂度:O(5*n*2*logn) 因为数据太大,不能作为下标使用。原创 2012-07-28 13:10:40 · 730 阅读 · 0 评论 -
HDU 4331 - Image Recognition
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4331 方法一是由我写的求实体矩阵个数的DP + 怪叔叔的YY暴力法(结果证明貌似时间复杂度不是很高)。 方法二是参照CJ牛讲的,用优先队列维护,用树状数组求个数。 ========================================================原创 2012-08-03 09:56:40 · 585 阅读 · 0 评论