题目连接

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. linux下软件的种类和对应的安装及卸载的方式

    转: 一个Linux应用程序的软件包中可以包含两种不同的内容: 1)一种就是可执行文件,也就是解开包后就可以直接运行的.在Windows中所 有的软件包都是这种类型.安装完这个程序后,你就可以使用,但 ...

  2. window.open()打开新窗口被拦截

    window.open( url )是常用的打开新页面的方法,一般都没有问题,但是如果在ajax回调方法里面使用就会被浏览器拦截,因为在浏览器安全机制中,页面弹窗必须是由用户触发的才是安全弹窗,比如说 ...

  3. 七 Kafka Streams VS Consumer API

    1 kafka Streams:   概念: 处理和分析储存在Kafka中的数据,并把处理结果写回Kafka或发送到外部系统的最终输出点,它建立在一些很重要的概念上,比如事件时间和消息时间的准确区分, ...

  4. ubuntu 14.04使用root登陆出现错误“Error found when loading /root/.profile”解决

    在刚修改完root权限自动登录后,发现开机出现以下提示: Error found when loading /root/.profile stdin:is not a tty ----........ ...

  5. Angular2快速入门-2.创建一个新闻列表

    背景: 我们想通过一个例子,展示下Angular2 怎么绑定页面,怎么创建Component, 例子:我们创建一个新闻列表,当点击新闻列表中某一条新闻的时候,展示出该条新闻的详细信息, 在详细信息中可 ...

  6. 【光速使用开源框架系列】图片加载框架ImageLoader

    [关于本系列] 最近看了不少开源框架,网上的资料也非常多,但是我认为了解一个框架最好的方法就是实际使用.本系列博文就是带领大家快速的上手一些常用的开源框架,体会到其作用. 由于作者水平有限,本系列只会 ...

  7. Express的路由详解

    Express的路由详解 http://www.jb51.net/article/76203.htm

  8. Django中间件CsrfViewMiddleware源码分析

    Django Documentation csrf保护基于以下: 1, 一个CSRF cookie基于一个随机生成的值,其他网站无法得到,次cookie有CsrfViewMiddleware产生.它与 ...

  9. php学习第一天-勤劳致富

    所谓“勤劳致富”,是很有科学依据的,且是经过我的亲身实践的. 自毕设突然转变为开发项目之后,整个天都变了.先是妹子给我订的票被强行取消,然后又是师兄的一句“***一小时就搞定了”,说明一下这个***是 ...

  10. 168. Excel Sheet Column Title 由数字返回excel的标题

    [抄题]: Given a positive integer, return its corresponding column title as appear in an Excel sheet. F ...