随笔分类 -  树状数组

hdu 4638 Group
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4638问题其实就是求[L,R]中有多少个连续的段若每一个人都是一个段 那么[L,R]中每一个朋友关系就会减少一个段(因为它将两个段合并了)我们把每个朋友关系变成一个边 要求[L,R]有多少个边 可以用到 离散化+树状数组把每个朋友关系形成的边以左端点为key从大到小排序 遍历时将右端点不断的插入当左端点为key的边全部插入的时候 那么所有[L,R]中L等于key的询问都可求了代码:#include#include#include#include#include#include#include#include# 阅读全文
posted @ 2013-08-01 18:45 夜-> 阅读(239) 评论(0) 推荐(0) 编辑
hdu 4630 No Pain No Game
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4630离散化+树状数组将数组 *a 从后向前遍历 遍历到 a[x] 的时候 再枚举a[x]的约数 假如 约数 klast[k] 对应到 上一个k出现的位置 那么可被公约数 k 更新的区间是 last[k] --- 最后把所有a[x]的约数都处理完之后 从 x 到任意 y(y>=x)形成的段的 最优解都可求代码:#include#include#include#include#include#include#include#include#includeusing namespace std;typede 阅读全文
posted @ 2013-07-31 20:32 夜-> 阅读(221) 评论(0) 推荐(0) 编辑
poj 3378 Crazy Thairs
摘要:http://poj.org/problem?id=3378要想求以第k个数为5个数中最后一个数的组合数量就要求从1到k-1这些数中比第k个小且是4个数中最后一个数的这些组合数量 之和依次类推求和用树状数组来维护 最后结果可能超long long 我用了大整数代码:#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<map>#include<vector>#include<stack>#include<se 阅读全文
posted @ 2013-02-19 21:18 夜-> 阅读(171) 评论(0) 推荐(0) 编辑
hdu 4417 Super Mario
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4417线段树 or 树状数组 都可以先把问题 和 和 砖块 分别按高度排序在求解区间答案时 根据要求的高度 将小于这个高度的砖块全部插入 再求解即可代码:#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <queue>#include <vector>#include <algorithm>#define LL lon 阅读全文
posted @ 2012-09-26 10:16 夜-> 阅读(245) 评论(0) 推荐(0) 编辑
poj 3321 Apple Tree
摘要:http://poj.org/problem?id=3321题目大意:给你N个点组成的树 每个点初始化为1 有两种操作C x:改变点的值 是1变0 是0变1Q x:问以x为根的子树上点值的和思路:主要是把树映射到树状数组中一遍dfs把点重新编号 low和high low表示刚搜到此点时的计数,high是搜玩其子树内所有节点后回来的计数编号比如说又n个点那么根节点1的low=1,high=2*n这样就映射到树状数组中啦。代码及其注释:#include<iostream>#include<cstdio>#include<cstring>#include<s 阅读全文
posted @ 2012-07-16 08:44 夜-> 阅读(174) 评论(0) 推荐(0) 编辑
poj 1195 Mobile phones
摘要:http://poj.org/problem?id=1195二维树状数组就是比一维的多了一维而已 关键在理解代码:#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<queue>#include<algorithm>#include<stack>using namespace std;const int N=1200;int c[N][N];int n;int lowbi 阅读全文
posted @ 2012-07-15 19:53 夜-> 阅读(161) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示