题目连接

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

Description

Fleeting time does not blur my memory of you. Can it really be 4 years since I first saw you? I still remember, vividly, on the beautiful Zhuhai Campus, 4 years ago, from the moment I saw you smile, as you were walking out of the classroom and turned your head back, with the soft sunset glow shining on your rosy cheek, I knew, I knew that I was already drunk on you. Then, after several months’ observation and prying, your grace and your wisdom, your attitude to life and your aspiration for future were all strongly impressed on my memory. You were the glamorous and sunny girl whom I always dream of to share the rest of my life with. Alas, actually you were far beyond my wildest dreams and I had no idea about how to bridge that gulf between you and me. So I schemed nothing but to wait, to wait for an appropriate opportunity. Till now — the arrival of graduation, I realize I am such an idiot that one should create the opportunity and seize it instead of just waiting.

These days,
having parted with friends, roommates and classmates one after another, I
still cannot believe the fact that after waving hands, these familiar
faces will soon vanish from our life and become no more than a memory. I
will move out from school tomorrow. And you are planning to fly far far
away, to pursue your future and fulfill your dreams. Perhaps we will
not meet each other any more if without fate and luck. So tonight, I was
wandering around your dormitory building hoping to meet you there by
chance. But contradictorily, your appearance must quicken my heartbeat
and my clumsy tongue might be not able to belch out a word. I cannot
remember how many times I have passed your dormitory building both in
Zhuhai and Guangzhou, and each time aspired to see you appear in the
balcony or your silhouette that cast on the window. I cannot remember
how many times this idea comes to my mind: call her out to have dinner
or at least a conversation. But each time, thinking of your excellence
and my commonness, the predominance of timidity over courage drove me
leave silently.

Graduation, means the end of life in university,
the end of these glorious, romantic years. Your lovely smile which is my
original incentive to work hard and this unrequited love will be both
sealed as a memory in the deep of my heart and my mind. Graduation, also
means a start of new life, a footprint on the way to bright prospect. I
truly hope you will be happy everyday abroad and everything goes well.
Meanwhile, I will try to get out from puerility and become more
sophisticated. To pursue my own love and happiness here in reality will
be my ideal I never desert.

Farewell, my princess!

If
someday, somewhere, we have a chance to gather, even as gray-haired man
and woman, at that time, I hope we can be good friends to share this
memory proudly to relight the youthful and joyful emotions. If this
chance never comes, I wish I were the stars in the sky and twinkling in
your window, to bless you far away, as friends, to accompany you every
night, sharing the sweet dreams or going through the nightmares
together.

Here comes the problem: Assume the sky is a flat plane.
All the stars lie on it with a location (x, y). for each star, there is
a grade ranging from 1 to 100, representing its brightness, where 100
is the brightest and 1 is the weakest. The window is a rectangle whose
edges are parallel to the x-axis or y-axis. Your task is to tell where I
should put the window in order to maximize the sum of the brightness of
the stars within the window. Note, the stars which are right on the
edge of the window does not count. The window can be translated but
rotation is not allowed.

Input

There are several test cases in the input. The first line of each case
contains 3 integers: n, W, H, indicating the number of stars, the
horizontal length and the vertical height of the rectangle-shaped
window. Then n lines follow, with 3 integers each: x, y, c, telling the
location (x, y) and the brightness of each star. No two stars are on the
same point.

There are at least 1 and at most 10000 stars in the sky.
1<=W,H<=1000000, 0<=x,y<2^31.

Output

For each test case, output the maximum brightness in a single line.

Sample Input

3 5 4
1 2 3
2 3 2
6 3 1
3 5 4
1 2 3
2 3 2
5 3 1

Sample Output

5
6

HINT

将点转化成矩形。

题意

给你一个w*h的矩形,和N个点,每个点都有一个权值,然后你用这个矩形去圈住他们,然后问你矩形所能圈住的最大权值是多少?

记得是多测哦。

题解:

我们可以反过来想有每个点(x,y)可以被哪些举行框住呢?(建议先想一下再往后看)
显然右上角在(x,y)到(x+W,y+H)到的矩形都可以框住(x,y),所以对于每个点(x,y),我们将(x,y)到(x+W,y+H)的区域加上相应的权值。
这样题目就转化成了求N个矩形中,权值最大的点。
之后直接上扫描线,类似求矩形的并集,唯一不同是对于每一条扫描线我们记录的是最大值。
 
最后记得开long long 但是不要像我蒟蒻一样开全局long long

代码:

//#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 100050
#define LL long long
LL cnt,tot,n,W,H,kth[N<<];
struct Query
{
LL l,r,h,id;
bool operator <(const Query &b)const
{return h==b.h?id<b.id:h<b.h;}
}que[N<<];
struct Tree{LL l,r,j,max;}tr[N<<];
template<typename T>void read(T&x)
{
LL k=;char c=getchar();
x=;
while(!isdigit(c)&&c!=EOF)k^=c=='-',c=getchar();
if(c==EOF)exit();
while(isdigit(c))x=x*+c-'',c=getchar();
x=k?-x:x;
}
void push_up(LL x)
{
tr[x].max=tr[x].j;
if (tr[x].r-tr[x].l>)
tr[x].max+=max(tr[x<<].max,tr[x<<|].max);
}
void bt(LL x,LL l,LL r)
{
tr[x]=Tree{l,r,,};
if(r-l==)return;
LL mid=(l+r)>>;
bt(x<<,l,mid);
bt(x<<|,mid,r);
}
void update(LL x,LL l,LL r,LL tt)
{
if (l<=tr[x].l&&tr[x].r<=r)
{
tr[x].j+=tt;
push_up(x);
return;
}
LL mid=(tr[x].l+tr[x].r)>>;
if (l<mid)update(x<<,l,r,tt);
if (mid<r)update(x<<|,l,r,tt);
push_up(x);
}
void input()
{
read(n); read(W); read(H);
LL x1,y1,x2,y2,tt;
for(LL i=;i<=n;i++)
{
read(x1); read(y1); read(tt);
x2=x1+W; y2=y1+H;
que[++tot]=Query{x1,x2,y1,tt};
que[++tot]=Query{x1,x2,y2,-tt};
kth[++cnt]=x1;
kth[++cnt]=x2;
kth[++cnt]=y1;
kth[++cnt]=y2;
}
}
void work()
{
sort(que+,que+tot+);
sort(kth+,kth+cnt+);
cnt=unique(kth+,kth+cnt+)-kth-;
bt(,,cnt);
LL l,r,ans=;
for(LL i=;i<=tot-;i++)
{
l=lower_bound(kth+,kth+cnt+,que[i].l)-kth;
r=lower_bound(kth+,kth+cnt+,que[i].r)-kth;
update(,l,r,que[i].id);
ans=max(ans,tr[].max);
}
printf("%lld\n",ans);
}
void clear(){cnt=;tot=;}
int main()
{
#ifndef ONLINE_JUDGE
freopen("aa.in","r",stdin);
#endif
while()
{
clear();
input();
work();
}
}

Stars in Your Window(线段树求最大矩形交)的更多相关文章

  1. 【POJ-2482】Stars in your window 线段树 + 扫描线

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11706   Accepted:  ...

  2. POJ 2482 Stars in Your Window 线段树扫描线

    Stars in Your Window   Description Fleeting time does not blur my memory of you. Can it really be 4 ...

  3. POJ 2482 Stars in Your Window 线段树

    如果按一般的思路来想,去求窗户能框住的星星,就很难想出来. 如果换一个思路,找出每颗星星能被哪些窗户框住,这题就变得非常简单了. 不妨以每个窗户的中心代表每个窗户,那么每颗星星所对应的窗户的范围即以其 ...

  4. POJ 2482 Stars in Your Window (线段树区间合并+扫描线)

    这题开始一直被矩形框束缚了,想法一直都是枚举线,但是这样枚举都需要O(n^2)...但是看了别人的思路,感觉这题思想真心很好(PS:开头好浪漫的描述啊,可惜并没有什么用)  题意就是在平面上给你一些星 ...

  5. poj2823Sliding Window(线段树求最值)

    链接 裸线段树 这题时间卡的挺棒 #include <iostream> #include<cstdio> #include<cstring> #include&l ...

  6. POJ 2482 Stars in Your Window(线段树+扫描线)

    题目链接 非常不容易的一道题,把每个点向右上构造一个矩形,将问题转化为重合矩形那个亮度最大,注意LL,注意排序. #include <cstdio> #include <cstrin ...

  7. POJ 2823 Sliding Window 线段树区间求和问题

    题目链接 线段树区间求和问题,维护一个最大值一个最小值即可,线段树要用C++交才能过. 注意这道题不是求三个数的最大值最小值,是求k个的. 本题数据量较大,不能用N建树,用n建树. 还有一种做法是单调 ...

  8. 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)

    原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...

  9. UVA 11983 Weird Advertisement --线段树求矩形问题

    题意:给出n个矩形,求矩形中被覆盖K次以上的面积的和. 解法:整体与求矩形面积并差不多,不过在更新pushup改变len的时候,要有一层循环,来更新tree[rt].len[i],其中tree[rt] ...

随机推荐

  1. VirtualBox 虚拟机 centos7 下 设置静态ip 并支持 xshell 远程登陆的设置方法

    1.设置虚拟机使用“桥接模式” 2.使用 vi /etc/sysconfig/network-scripts/ifcfg-enp0s3  打开配置文件(其中 enp0s3 是你的linux的网卡名,在 ...

  2. web.config 权限设置

    <system.web> <authorization> <!--未登陆用户不可以访问--> <deny users="?" /> ...

  3. [置顶] STM32 输入捕获的脉冲宽度及频率计算

    输入捕获模式可以用来测量脉冲宽度或者测量频率.STM32 的定时器,除了 TIM6 和 TIM7,其他定时器都有输入捕获功能.以下是对脉冲宽度及频率的计算. 1.脉冲宽度 如下图所示,采集该高电平脉冲 ...

  4. Git第三方仓库安装方式(IUS)

    1.安装使用里面说的自动化安装脚本 curl https://setup.ius.io | sh 2.然后可以看到 git2u相关内容 yum search git 3.执行安装,并查看下版本 yum ...

  5. Android 4 学习(10):Adapters简介

    参考<Professional Android 4 Development> Adapters简介 Adapter用于将数据和实现AdapterView接口的ViewGroup绑定在一起. ...

  6. MongoDB在Java下的增删查改

    我们总不能一直使用cmd对数据库操作,数据库总是要在程序中使用的.今天来说一下怎么通过Java调用MongoDB. 学习一下最基本也是最常用的增删查改语句,这是使用数据库的基础. 注意事项: 1.要打 ...

  7. Deep Learning(深度学习)学习笔记整理系列

    http://blog.csdn.net/zouxy09/article/details/8775360 http://blog.csdn.net/zouxy09/article/details/87 ...

  8. [原创]Mybatis特殊值Enum类型转换器-ValuedEnumTypeHandler

    引言 typeHandlers 阅读官方文档 typeHandlers 一节{:target="_blank"} MyBatis 在预处理语句(PreparedStatement) ...

  9. 常用的正则规则,直接copy就OK了

    import  re #用户名验证:(数字字母或下划线6到20位)re.match("/^\w{6,20}$/",匹配对象) #邮箱验证: re.match(" /^[a ...

  10. 配置Linux的SSH双重认证

    背景:双因子认证(简称:2FA,以下简称2FA),在这里其为SSH的第二重认证.2FA指的是密码以及实物(信用卡.SMS手机.令牌或指纹等生物标志)两种条件对用户进行认证的方法.通过两种不同的认证程序 ...