树状数组
Joyyiwei
这个作者很懒,什么都没留下…
展开
-
UVALive - 2191 Potentiometers
题意:S操作将x改为y,M操作求[x,y]的和思路:稍加改动一下树状数组就行了,当然线段树也可以#include #include #include #include using namespace std;const int MAXN = 400005;int n,t[MAXN];int lowbit(int x){ return x&(-x);}void原创 2014-02-23 19:26:06 · 1060 阅读 · 0 评论 -
HDU - 4267 A Simple Problem with Integers(树状数组的逆操作)
DescriptionLet A1, A2, ... , AN be N elements. You need to deal with two kinds of operations. One type of operation is to add a given number to a few numbers in a given interval. The other is to q原创 2014-10-18 16:38:50 · 864 阅读 · 0 评论 -
HDU Always Cook Mushroom (极角排序+树状数组)
Problem DescriptionMatt has a company, Always Cook Mushroom (ACM), which produces high-quality mushrooms. ACM has a large field to grow their mushrooms. The field can be considered as a 1000 *原创 2014-10-30 23:24:32 · 1024 阅读 · 0 评论 -
UVA - 11610 Reverse Prime
题意:首先定义了一种叫做Reverse Prime的数:是一个7位数,倒置后是一个 然后要把所有的Reverse Prime求出来,排好序。 然后题目有2种操作: q x :求编号0到编号x的Reverse Prime的质因数个数的和 d x :从表中删掉x(x是一个Reverse Prime)思路:首先筛选出所有的素数,然后倒置,因为我们的素数都是#include原创 2014-05-18 12:05:05 · 1354 阅读 · 0 评论 -
HDU - 3030 Increasing Speed Limits
题意:求有长为m的序列生成的长度为n的序列的上升子序列的个数思路:生成完长为n的序列后,首先我们想到(nlogn)的求上升序列的方法,然后再这个基础上改进,每插入一个的时候,我们可以得到左边的小于它的个数,然后我们就可以得新增加的上升子序列是sum(id-1)+1,然后更新树状数组#include #include #include #include #define ll long原创 2014-04-12 15:55:52 · 1257 阅读 · 0 评论 -
HDU - 3015 Disharmony Trees
题意:给你n棵树的坐标x,高度h,让你分别按坐标,高度排序后,得到一新的序列,也可以理解为一颗组合成的新树,这棵树的坐标,高度都是排序来的,看了别人的解释,还是理解了老半天,然后就是求花费了,每任意两颗树的花费为min(h[i],h[j])*abs(x[i]-x[j]),求所有组合的花费思路:经过排序的处理后,就是仿着POJ-1990 的思想来做 了,也可以简化成:按高度排序后,然后按每棵原创 2014-04-07 12:49:29 · 971 阅读 · 0 评论 -
HDU - 2838 Cow Sorting (树状数组)
题意:求排列成升序的花费,每次只能交换相邻的两个数,且话费为两个数字的和,求最小的话费思路:先设想一下,每个数字会被交换的可能,一个是当前面有大于它的数字,一个是当后面有小于它的数字两种情况,这样我们就可以联想到树状数组了,每次看看该数面有多少小于它的,就可以求出多少大于它的了,然后倒着求小于它的情况,起初一直挖,改着改着就A了,还有太大的数组一定要定义成全局变量#include #in原创 2014-04-05 10:25:24 · 783 阅读 · 0 评论 -
POJ - 1990 MooFest
题意:一排牛,每头牛(坐标pos,听力v),如果牛i和牛j交流的话,需要max{v[i],v[j]}*abs(pos[i]-pos[j]),求两两交流的总和。思路:还是求逆序数对的思想,按坐标排序后,求当前小于它听力的牛们的总花费,然后倒序后再求一遍就是结果了,#include #include #include #include using namespace std;const原创 2014-04-05 15:42:16 · 1272 阅读 · 0 评论 -
HDU - 2688 Rotate
题意:很容易理解,求每次序列的顺序数思路:要用到线段数,不然会超时,第一次处理的时候,用线段树每次来查询树的相对的位置的前几个的个数,之后交换的时候,判断用第一个交换数的大小就可以计算个数了 ,注意输出,用cout过的#include #include #include #include using namespace std;const int MAXN = 3000005;原创 2014-04-01 22:20:54 · 923 阅读 · 0 评论 -
HDU - 2642 Stars
题意:就是求每个矩形内的亮的星星的个数思路:二维的树状数组,相当于优化了的矩阵求和的题目#include #include #include #include using namespace std;const int MAXN = 1005;int arr[MAXN][MAXN];int vis[MAXN][MAXN];int lowbit(int x){ retu原创 2014-04-14 22:44:49 · 754 阅读 · 0 评论 -
HDU - 1541 Stars
题意:每颗星的左下角的星星的个数就是它的等级,求所有等级的星星个数思路:因为已经按y坐标排序了,所以只要线段树x坐标就行了#include #include #include #include using namespace std;const int MAXN = 32005;int tree[MAXN],level[MAXN];int n;int lowbit(in原创 2014-04-14 18:08:03 · 783 阅读 · 0 评论 -
HDU - 3465 Life is a Line
题意:求在[L,R]范围内直线交点的对数思路:首先如果两条直线相交的话,那么(xl1-xl2)*(yl1-yl2)#include #include #include #include #define ll long longusing namespace std;const int MAXN = 50010;struct node{ double x,y; int i原创 2014-04-14 16:02:23 · 1008 阅读 · 0 评论 -
HDU - 2227 Find the nondecreasing subsequences
题意:求不递减的子序列的个数思路:跟昨天那题HDU-3030不同的是,昨天的是严格的递增的子序列数,稍微修改一下就行了#include #include #include #include #define ll long longusing namespace std;const int MOD = 1000000007;const int MAXN = 100010;ll原创 2014-04-13 15:34:31 · 775 阅读 · 0 评论 -
HDU - 3450 Counting Sequences
题意:求个数大于等于2的序列,要求每相邻的两个的大于d,求满足的个数思路:同样是树状数组的应用,跟前面两题类似,求每次加入的a[i],先求范围在[a[i]-d,a[i]+d]的个数,再加到a[i]上,加一加的是本身,还有要注意的是,要减去1个的情况,跟前面两题不一样,#include #include #include #include using namespace std;c原创 2014-04-13 23:39:12 · 897 阅读 · 0 评论 -
POJ - 2352 Stars (树状数组)
题意:给你星星的坐标(Y递增,若Y相等则X递增),每个星星有个等级,规定它的等级是它左下方的星星个数,输出所有星星的等级思路:树状数组#include #include #include #include using namespace std;const int MAXN = 32010;int n,lev[MAXN],c[MAXN];void add(int x,in原创 2014-03-03 23:25:05 · 1018 阅读 · 0 评论 -
UVALive - 4329 Ping pong (树状数组)
题意:一条街上住着n个乒乓球爱好者要组织比赛,每场比赛需要3个人,两个选手一个裁判,他们有一个奇怪的规定,即裁判必须住在两个选手之间,而且能力值也在两个选手之间,问一共能有几场比赛思路:考虑第i个人当裁判的情形,假设a1到ai-1中有ci个比ai小,那么就有(i-1)-ci个比ai大同理可以得到在ai+1到an的情况,那么就一共有:ci*(n-i-di)+di*(i-ci-1)种情况然原创 2014-02-18 22:19:29 · 1014 阅读 · 2 评论 -
UVALive - 5902 Movie collection
题意:1~n按从上到下排列,m次询问,每次问x之前的有多少个数字,并且将x放到队首思路:树状数组,首先将1~n下标向后移m位,每次询问后都将一个数字移到队首,每次都更新了节点的大小,并且问到了前缀和,所以用树状数组#include #include #include #include using namespace std;const int MAXN = 201010;原创 2014-02-23 20:40:26 · 1057 阅读 · 0 评论 -
POJ - 2481 Cows(树状数组)
DescriptionFarmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one-dimensional number line) in his field is particularly good.原创 2014-10-18 22:38:10 · 918 阅读 · 0 评论