51nod 1208 && POJ 2482:Stars in Your Window【普通线段树】
来源:互联网 发布:阴司守门人网络剧资源 编辑:程序博客网 时间:2024/06/08 00:15
1208 Stars in Your Window
题目来源: Poj
基准时间限制:2 秒 空间限制:131072 KB 分值: 160 难度:6级算法题 收藏 关注
整点上有N颗星星,每颗星星有一个亮度。用一个平行于x轴和y轴,宽为W高为H的方框去套星星。套住的所有星星的亮度之和为S(包括边框上的星星),求S的最大值。
Input
第1行:共3个数N, W, H,中间用空格分割,N为星星的数量,W为方框的宽度,H为方框的高度。(2 <= N <= 50000, 1 <= W, H <= 10^9)
第2 - N + 1行:每行3个数,X, Y, L,中间用空格分隔,分别表示星星的横坐标X,纵坐标Y,以及星星的亮度L。(1 <= X, Y <= 10^9,1 <= L <= 10000)
Output
输出方框能够套住的最大亮度和S。
Input示例
6 3 3
1 1 2
2 2 3
3 3 4
4 4 3
5 5 2
6 6 1
Output示例
12
#include <stdio.h>#include <bits/stdc++.h>#define mod 1000000007typedef long long ll;using namespace std;class P{ public: ll x,x1,y,l;};int cmp(P a,P b){ if(a.y==b.y)a.l>b.l; return a.y<b.y;}P s[100005];ll a[100005],tree[8*50005],add[8*50005];ll n,w,h,num,ans;void push_down(int i){ tree[i*2]+=add[i];tree[i*2+1]+=add[i]; add[i*2]+=add[i];add[i*2+1]+=add[i]; add[i]=0;} void update(int i,int l,int r,int x,int y,int lg){ if(x<=l && y>=r){ add[i]+=lg; tree[i]+=lg; return; } int mid=l+r>>1; push_down(i); if(x<=mid) update(i*2,l,mid,x,y,lg); if(y>mid) update(i*2+1,mid+1,r,x,y,lg); tree[i]=max(tree[i*2],tree[i*2+1]);}int main(){ cin>>n>>w>>h; for(int i=1;i<=n;i++){ scanf("%lld%lld%lld",&s[i].x,&s[i].y,&s[i].l); s[i].x1=s[i].x+w;s[i+n].x=s[i].x; s[i+n].x1=s[i].x1;s[i+n].y=h+s[i].y;s[i+n].l=-s[i].l; a[i]=s[i].x;a[i+n]=s[i].x1; } sort(a+1,a+1+n+n); sort(s+1,s+1+n+n,cmp); num=unique(a+1,a+1+n+n)-a-1; for(int i=1;i<=2*n;i++){ int k1=lower_bound(a+1,a+1+num,s[i].x)-a; int k2=lower_bound(a+1,a+1+num,s[i].x1)-a; update(1,1,num,k1,k2,s[i].l); ans=max(ans,tree[1]); } cout<<ans<<endl; return 0;}
0 0
- 51nod 1208 && POJ 2482:Stars in Your Window【普通线段树】
- 51nod 1208 && 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 线段树
- Stars in Your Window - POJ 2482 线段树
- 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-线段树+扫描线)
- Delphi 设置或者检查应用程序自动启动功能
- 完美解决非MBR引导下的WIN7激活问题
- jfinal编码问题及解决
- OpenGL ES
- ListView2——Android群英传
- 51nod 1208 && POJ 2482:Stars in Your Window【普通线段树】
- 虚指针的对齐_boolan_第二门课_第一周_作业
- ElasticsearchCRUD使用(十三)【Elasticsearch谷歌地图搜索的MVC应用】
- linux上ActiveMQ 集群安装、配置和高可用测试
- 选择排序算法
- ROS多机通信
- You-Dont-Know-JS
- HBuilder连接夜神模拟器
- Ubutu 17.04 WiFi热点创建