poj 2482 Stars in Your Window (线段树扫描线)
来源:互联网 发布:网络信息安全技术 编辑:程序博客网 时间:2024/05/19 14:02
题目大意:
求一个窗口覆盖最多的星星的权值。
思路分析:
每一个星星看成
左下点为x y
右上点为x+w-1 y+h-1 的矩形。
然后求出最大覆盖的和。
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#define lson num<<1,s,mid#define rson num<<1|1,mid+1,e#define maxn 10005using namespace std;typedef long long LL;LL res[maxn<<4];LL sum[maxn<<4];LL x[maxn<<4];struct node{ LL s,e,h,type; bool operator < (const node &cmp)const { if(h==cmp.h)return type>cmp.type; return h<cmp.h; }}scline[maxn<<1];void pushup(int num){ sum[num]=max(sum[num<<1],sum[num<<1|1]);}void pushdown(int num){ if(res[num]) { sum[num<<1]+=res[num]; sum[num<<1|1]+=res[num]; res[num<<1]+=res[num]; res[num<<1|1]+=res[num]; res[num]=0; }}void build(int num,int s,int e){ res[num]=0; sum[num]=0; if(s==e)return; int mid=(s+e)>>1; build(lson); build(rson);}void update(int num,int s,int e,int l,int r,LL val){ if(l<=s && r>=e) { res[num]+=val; sum[num]+=val; return; } int mid=(s+e)>>1; pushdown(num); if(l<=mid)update(lson,l,r,val); if(r>mid)update(rson,l,r,val); pushup(num);}int main(){ LL n,w,h; while(cin>>n>>w>>h) { for(int i=1;i<=n;i++) { LL ts,te,tt; cin>>ts>>te>>tt; scline[i*2-1].s=ts,scline[i*2-1].e=ts+w-1,scline[i*2-1].h=te,scline[i*2-1].type=tt; scline[i*2].s=ts,scline[i*2].e=ts+w-1,scline[i*2].h=te+h-1,scline[i*2].type=-tt; x[i*2-1]=ts,x[i*2]=ts+w-1; } sort(scline+1,scline+1+n*2); sort(x+1,x+1+n*2); int m=unique(x+1,x+1+n*2)-x; build(1,1,m); LL ans=0; for(int i=1;i<=n*2;i++) { int l=lower_bound(x+1,x+m,scline[i].s)-x; int r=lower_bound(x+1,x+m,scline[i].e)-x; update(1,1,m,l,r,scline[i].type); ans=max(ans,sum[1]); } cout<<ans<<endl; } return 0;}/*2 1 50 0 1000 4 101*/
0 0
- poj 2482 Stars in Your Window(线段树+扫描线)
- poj 2482 Stars in Your Window(线段树+扫描线)
- poj 2482 Stars in Your Window(线段树,扫描线)
- 【POJ】2482 Stars in Your Window 线段树 + 扫描线
- POJ 2482 Stars in Your Window(线段树扫描线)
- POJ 2482 Stars in Your Window (线段树扫描线)
- poj 2482 Stars in Your Window 线段树 扫描线
- POJ 2482 Stars in Your Window 线段树+扫描线
- POJ 2482(Stars in Your Window-线段树+扫描线)
- poj 2482 Stars in Your Window 扫描线 线段树
- POJ 2482 Stars in Your Window(线段树扫描线)
- poj 2482 Stars in Your Window (线段树+平面扫描)
- poj 2482 Stars in Your Window(线段树+离散化+扫描线)
- poj 2482 Stars in Your Window (线段树扫描线)
- POJ 2482 stars in your window(线段树 , 扫描线)
- poj 2482 Stars in Your Window(线段树+扫描线+离散化)
- 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)
- 【POJ 2482】Stars in Your Window(扫描线+线段树)
- CF 148D Bag of mice 概率DP
- codeforces 256 div2 C
- 销售税面试题九编码实现之log4j配置文件
- POJ 1789 Truck History 最小生成树
- 设计模式-适配器模式
- poj 2482 Stars in Your Window (线段树扫描线)
- Qt笔记——QString
- 用MFC实现“查找/替换”对话框
- 使用SQL Server 获取插入记录后的自增ID(自动编号)
- Tomcat的bin下的startup.bat打开一闪而过
- vmlinux-dirs-2.doc
- java与数据结构
- andriod 在windows上环境配置
- 反转单链表