
线段树
凌阡陌
随心而为,我自逍遥
展开
-
poj2528线段树+离散化
离散化:把无限空间中有限的个体映射到有限的空间中去,以此来提高算法的时空效率。基本思想:在众多的可能的情况中“中考虑我需要的值”。大致题意:在一面墙上贴海报,可覆盖,求最终露出来的海报的个数。由于数据范围较大,所以想到离散化,把数据进行排序,在排序之后将下标号作为新的数值进行计算,之后就利用线段树。#include #include #include #include us原创 2012-05-14 11:05:12 · 271 阅读 · 0 评论 -
hdu4325线段树+离散化
首先将所有点进行离散化,然后利用线段树求解。#include #include #include using namespace std;const int maxn=500100;struct Node{ int l,r,c; int add;}tree[maxn*4];int X[maxn*4];int tmp[maxn];int set[maxn][2原创 2012-08-05 16:16:52 · 302 阅读 · 0 评论 -
upper_bound\lower_bound的用法
#include #include //必须包含的头文件using namespace std;int main(){ int point[10] = {1,3,7,7,9}; int tmp = upper_bound(point, point + 5, 7) - point;//按从小到大,7最多能插入数组point的哪个位置 printf("%d\n",tmp); tmp = l原创 2012-08-05 16:15:36 · 339 阅读 · 0 评论 -
poj2828
题目描述:插队问题,可以用线段树和树状数组来解决。这里只给出线段树的做法,因为最后一个人要站的位置一定是他想站的位置,所以考虑逆序输入,假如他要站在n位置,有两种情况,(1)如果要站的位置在前一半就能够站的下,那么他就站在第n个空位上(2)否则,他要站的位置减去前一半被占满的人数,然后站在后一半。用线段树解即可。#include #include #include using names原创 2012-05-24 20:13:16 · 268 阅读 · 0 评论 -
线段树题目
hdu 3275 1166 1754 1542 3525 1394 3911 1823 4027 2795 3627 1255(矩形面积的交)1828(矩形的周长)3308(省赛类似)poj 1151 1177 1823 2104 2155 2299 2352 2482 25282761 2777 2823 2828 2886 3264 3277 34683667 3695推荐:p原创 2012-06-06 13:21:25 · 288 阅读 · 0 评论 -
poj1151(hdu 1542)线段树+离散化
题意:求矩形并区域面积的总和。利用线段树来解决这个问题,首先将这个矩形投影到x轴(y轴也可),同时记录矩形的高度,利用线段树找到相邻的两个x点,即矩形的长,然后再乘以矩形的高,即可得到矩形的一部分面积,再将这些面积加在一起,就可以得到矩形的面积。~纪念思考了一天多的题目~#include #include #include using namespace std;#define原创 2012-06-06 13:12:56 · 479 阅读 · 0 评论 -
省赛热身赛C
就是求一个百分位数,主要是没想到需要第一次将所有数据存起来,以后需要注意。。。只要是数据小的,都要考虑这个问题,既省时,有容易对。#include#include#include using namespace std;const int MAX=1000050;double price[MAX];double percentile[105];int main(){ int转载 2012-05-16 21:21:53 · 1551 阅读 · 0 评论 -
poj3468
#include #include using namespace std;#define maxn1 10000000#define maxn2 100005typedef struct{ int l,r; long long sum,store;}Tree;Tree tree[maxn1];long long v[maxn2];long long sum;原创 2012-05-16 10:42:01 · 258 阅读 · 0 评论 -
线段树模板
线段树应用:求面积:1) 坐标离散化2) 垂直边按x坐标排序3) 从左往右用线段树处理垂直边 累计每个离散x区间长度和线段树长度的乘积求周长:1) 坐标离散化2) 垂直边按x坐标排序, 第二关键字为入边优于出边3) 从左往右用线段树处理垂直边 在每个离散点上先加入所有入边, 累计线段树长度变化值 再删除所有出边, 累计线段树长度变化值4) 水平边按y坐标排序,原创 2012-05-15 20:14:18 · 235 阅读 · 0 评论 -
hdu1754 线段树
这题太恶心了!!!!大山炮题!!!就是一个简单的线段树,写慢一点都要超时!然后又会不知不觉就re!我到现在还不知道为什么会re!神经病题!就不能用if...else 只能用if#include #include using namespace std;#define maxn1 200010struct node{ int l,r,grade;}tree[maxn1原创 2012-06-03 21:40:07 · 244 阅读 · 0 评论 -
线段树
http://www.notonlysuccess.com/index.php/segment-tree/原创 2012-06-04 21:33:56 · 279 阅读 · 0 评论 -
hdu1166依旧是大山跑线段树题
也是不知不觉就会re 还不知道为什么 神经病题!害我做了这么长时间!!!Sample Input1101 2 3 4 5 6 7 8 9 10Query 1 3Add 3 6Query 2 7Sub 10 2Add 6 3Query 3 10End Sample OutputCase 1:63359#include #in原创 2012-06-03 21:42:34 · 548 阅读 · 0 评论 -
hdu3275线段树
#include #include using namespace std;#define maxn 100010char ch[maxn];struct Tree{ int l,r,store,len; bool lson,rson; bool flag;}tree[maxn*3];void build(int l,int r,int pos){原创 2012-06-02 20:00:45 · 282 阅读 · 0 评论 -
hdu4288线段树
题意:给三种操作,一种是想有序序列中加一个数,一个是向有序序列中删除一个数,还有一种是求这个有序序列中mod 5==3的数据之和。思路:建立一颗线段树,每个线段树都有6个域,mod[0...4]还有一个num[]用来记录每个区间内的个数。难点在于更新时。#include #include #include using namespace std;#define lson l,m,r原创 2012-09-18 14:23:43 · 343 阅读 · 0 评论