http://poj.org/problem?id=2482

类似于上一篇 这题转化的比较巧妙 将一个点转化为一个矩形(x,y, x+w,y+h),扫描线入值为正 出值为负

也就是一根线过去 每进入一个矩形 都更新线上的总值 取一个最大值

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define N 20010
#define LL long long
struct node
{
LL lx,rx,y,s;
node(){}
node(LL a,LL b,LL c,LL d):lx(a),rx(b),y(c),s(d){}
bool operator <(const node &S)const
{
if(y==S.y)
return s>S.s;
return y<S.y;
}
}te[N];
int sum[N<<],cov[N<<],que[N];
int bin(LL x,int n)
{
int s=,e = n,m;
while(s<=e)
{
m = (s+e)/;
if(que[m]==x)
return m;
else if(que[m]>x)
e = m-;
else
s = m+;
}
return m;
}
void pushdown(int w)
{
if(cov[w])
{
cov[w<<] += cov[w];
cov[w<<|] += cov[w];
sum[w<<] += cov[w];
sum[w<<|] += cov[w];
cov[w] = ;
}
}
void pushup(int w)
{
sum[w] = max(sum[w<<],sum[w<<|]);
}
void update(int a,int b,int d,int l,int r,int w)
{
if(a<=l&&b>=r)
{
sum[w]+=d;
cov[w]+=d;
return ;
}
pushdown(w);
int m = (l+r)>>;
if(a<=m)
update(a,b,d,l,m,w<<);
if(b>m)
update(a,b,d,m+,r,w<<|);
pushup(w);
}
int main()
{
int i,k,n;
LL w,h,x,y,v;
while(cin>>n>>w>>h)
{
int num = ;
w--;h--;
for(i = ; i <= n ;i++)
{
cin>>x>>y>>v;
que[num] = x;
te[num++] = node(x,x+w,y,v);
que[num] = x+w;
te[num++] = node(x,x+w,y+h,-v);
}
sort(que,que+num);
sort(te,te+num);
k = ;
for(i = ; i < num ; i++)
{
if(que[i]!=que[i-])
que[k++] = que[i];
}
int maxz = ;
for(i = ; i < num ; i++)
{
int l = bin(te[i].lx,k-);
int r = bin(te[i].rx,k-);
update(l,r,te[i].s,,k-,);
maxz = max(maxz,sum[]);
}
cout<<maxz<<endl;
}
return ;
}

poj2482Stars in Your Window(线段树+离散化+扫描线)的更多相关文章

  1. 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)

    [POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

  2. hdu1542 矩形面积并(线段树+离散化+扫描线)

    题意: 给你n个矩形,输入每个矩形的左上角坐标和右下角坐标. 然后求矩形的总面积.(矩形可能相交). 题解: 前言: 先说说做这道题的感受: 刚看到这道题顿时就懵逼了,几何 烂的渣渣.后来从网上搜题解 ...

  3. POJ1151Atlantis 矩形面积并[线段树 离散化 扫描线]

    Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21734   Accepted: 8179 Descrip ...

  4. POJ 1151Atlantis 矩形面积并[线段树 离散化 扫描线]

    Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21734   Accepted: 8179 Descrip ...

  5. hdu1542线段树+离散化+扫描线

    参考博客: http://blog.csdn.net/xingyeyongheng/article/details/8927732 总的来说就是用一条(假想的)线段去平行x轴从下往上扫描,扫描的过程中 ...

  6. Picture POJ - 1177 线段树+离散化+扫描线 求交叉图像周长

    参考  https://www.cnblogs.com/null00/archive/2012/04/22/2464876.html #include <stdio.h> #include ...

  7. POJ 1177/HDU 1828 picture 线段树+离散化+扫描线 轮廓周长计算

    求n个图矩形放下来,有的重合有些重合一部分有些没重合,求最后总的不规则图型的轮廓长度. 我的做法是对x进行一遍扫描线,再对y做一遍同样的扫描线,相加即可.因为最后的轮廓必定是由不重合的线段长度组成的, ...

  8. HDU 1542 线段树离散化+扫描线 平面面积计算

    也是很久之前的题目,一直没做 做完之后觉得基本的离散化和扫描线还是不难的,由于本题要离散x点的坐标,最后要计算被覆盖的x轴上的长度,所以不能用普通的建树法,建树建到r-l==1的时候就停止,表示某段而 ...

  9. Codeforces 610D Vika and Segments 线段树+离散化+扫描线

    可以转变成上一题(hdu1542)的形式,把每条线段变成宽为1的矩形,求矩形面积并 要注意的就是转化为右下角的点需要x+1,y-1,画一条线就能看出来了 #include<bits/stdc++ ...

随机推荐

  1. Get vertical scrollbar width and example

    $.scrollbarWidth = function () { var parent, child, width; if (width === undefined) { parent = $('&l ...

  2. 【Delphi】无标题移动窗体

    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Inte ...

  3. emoji处理方法汇总

    emoji资料 今天研究了emoji,挺有意思,资料挺多,摘要一些信息给大家分享,也算是自己记录学习. emoji介绍 Emoji (絵文字,词义来自日语えもじ,e-moji,moji在日语中的含义是 ...

  4. PL/SQL Developer编码格式设置及中文乱码解决方案

    1.PL/SQL Developer中文字段显示乱码 原因:因为数据库的编号格式和pl /sql developer的编码格式不统一造成的. 2.PL/SQL Developer编码格式设置详细的解决 ...

  5. UVA 725

    Description   Write a program that finds and displays all pairs of 5-digit numbers that between them ...

  6. WinForm调试输出数据

    在调试Winfrom时想知道其中的数据输出 1.单击运行按钮 2.选择调试->窗口->输出 3.单击Winform中要执行的按钮  在输出栏中显示输出数据 4.Ctrl  K  S  能够 ...

  7. Unity3d本地存储

    原文地址:http://blog.csdn.net/dingkun520wy/article/details/49386507 (一)简单数据存储PlayerPrefs 这种存储方法比较简单直接上代码 ...

  8. input输入框的各种样式

    输入框景背景透明: <input style="background:transparent;border:1px solid #ffffff"> 鼠标划过输入框,输入 ...

  9. 编写你的第一个 Django 程序 第2部分

    原地址:http://django-chinese-docs.readthedocs.org/en/latest/intro/tutorial02.html 本教程上接 教程 第1部分 . 我们将继续 ...

  10. hdu 4336 Card Collector 容斥原理

    读完题目就知道要使用容斥原理做! 下面用的是二进制实现的容斥原理,详见:http://www.cnblogs.com/xin-hua/p/3213050.html 代码如下: #include< ...