题目连接

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. file does not exist 阿里云OSS图片上传遇到的问题

    ./uploads\20171209/0497b8dd16e72c6fcf5bfd552f535a81.png file does not exist 原代码 function aliyun($sav ...

  2. python开发面向对象基础:组合&继承

    一,组合 组合指的是,在一个类中以另外一个类的对象作为数据属性,称为类的组合      人类装备了武器类就是组合 1.圆环,将圆类实例后传给圆环类 #!/usr/bin/env python #_*_ ...

  3. jquery添加和删除多个同名的input输入框

    <script type="text/javascript"> function del(obj){ $(obj).parents("li").re ...

  4. 14-jQuery的ajax

    什么是ajax AJAX  =  异步的JavaScript 和 XML (Asynchronous Javascript and XML) 简言之,在不重载整个网页的情况下,AJAX通过后台加载数据 ...

  5. 查看自己U盘格式

    转自:https://zhidao.baidu.com/question/220844418.html 选中U盘后,鼠标右键单击,选项菜单中点击属性,出的的属性窗口中的“常规”项里边就有U盘的基本信息 ...

  6. delphi 四舍五入

    trunc取整 四舍五入 formatfloat('0.00', 2.1850) 看第二位,然后对后面的数字处理,偶数的话舍去,奇数四舍五入 System.Math.RoundTo(tempval,- ...

  7. Dom对象与jQuery对象的转换

  8. 【更多教程关注公众号全要买】1-2 Disruptor与BlockingQueue压力测试性能对比

    JDK所提供的BlockingQueue替换成Dis

  9. IWebBrowser2不能复制剪切

    项目中嵌入了IE控件,近期做了一次大改版,发现网页不能进行复制和剪切了,折腾了半天,发现是com初始化有问题: 修正前的方式: CoInitialize(NULL); // do your work ...

  10. chrome浏览器-Toolbar工具条不显示

    来源于<sencha touch 权威指南> ------------------------------------ 工具条按钮在chrome下不显示,不知是不支持还是代码有问题.app ...