2012年2月8日

poj 2667 hotel 线段树

摘要: 基本和poj 1823 hotel基本一样 只需加一个find函数 1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 #define MAXN 50001 5 struct node 6 { 7 int lmax,rmax,max; 8 int left,right; 9 int flag; 10 int r; 11 }; 12 node tree[MAXN*4]; 13 void build(int i) 14 { 15 tree[i].lmax=tree[... 阅读全文

posted @ 2012-02-08 23:23 myoi 阅读(206) 评论(0) 推荐(0) 编辑

poj 1823 hotel 线段树

摘要: 题意:一个hotel,有n个连续的房间,开始时均无人住宿共有3种操作1 a b 从a开始连续b个房间全部旅客住宿 [a,a+b-1];2 a b从a开始连续b个房间全部旅客离开[a,a+b-1];3 查询最长连续空房间思路:线段树,记录每个节点,左边,右边各最多连续空房间lmax,rmax; 以及这个区间内最多空房间max 1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 #define MAXN 16001 5 struct node 6 { 7 int lmax,rmax,max; 8 . 阅读全文

posted @ 2012-02-08 22:06 myoi 阅读(489) 评论(0) 推荐(0) 编辑

poj 2482 Stars in Your Window 线段树

摘要: 题意:平面上有n个星星,给出每个星星的位置和亮度 求一个W*H的矩形(不包括边界)使得矩形内的星星亮度之和最大。思路:每个点(x,y,brightness) 存两个点(x,y,brightness)和(x,y+H,-brightness)先离散化从左到右两根间距为W的扫描线,左开右闭。依次把点加进线段树,下标是y,权值是brightness,题目所求的就是前i个点的和的最大值。线段树存当前范围内的sum,maxsum其中 maxsum[i]=max(maxsum[2*i],sum[2*i]+maxsum[2*i+1]);ans=max(maxsum[i]) 1 #include<iost 阅读全文

posted @ 2012-02-08 19:45 myoi 阅读(583) 评论(0) 推荐(1) 编辑

导航