题目连接

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. 表空间 -- tablespace

    表空间是数据库的逻辑划分,一个表空间只能属于一个数据库.所有的数据库对象都存放在指定的表空间中.但主要存放的是表, 所以称作表空间. Oracle数据库中至少存在一个表空间,即SYSTEM的表空间. ...

  2. python开发调用基础:模块的调用&制作包&软件开发规范

    一,包的调用 #!/usr/bin/env python #_*_coding:utf-8_*_ #调用 glance[1..4]\api\policy.py 路径 # policy.py 内容 # ...

  3. 消息队列函数(msgget、msgctl、msgsnd、msgrcv)及其范例

    消息队列函数由msgget.msgctl.msgsnd.msgrcv四个函数组成.下面的表格列出了这四个函数的函数原型及其具体说明. 1.   msgget函数原型 msgget(得到消息队列标识符或 ...

  4. windows下配置protobuf2.6.1

    步骤: 下载protobuf-2.6.1.zip和protoc-2.6.1-win32.zip,地址:https://github.com/google/protobuf/tags 到目录protob ...

  5. LINUX免密登陆

    ssh 无密码登录要使用公钥与私钥.linux下可以用用ssh-keygen生成公钥/私钥对,下面我以CentOS为例. 有机器A(192.168.1.155),B(192.168.1.181).现想 ...

  6. hadoop文件写入

    转:http://blog.csdn.net/xiaoshunzi111/article/details/48198105 由上图可知;写入文件分为三个角色,分别是clientnode  nameno ...

  7. 通过模板判断Value是否为指针

    有个参数,需要判断其Value是否为指针,如果是做相应的处理. 代码示例如下,后来发现is_pointer在std空间中. #include <stdio.h> #include<i ...

  8. linux的基本指令--第三节

    查找与检索: 一.文件名查找:find . -name "test*"      find 路径  查找类型  名字  未输入路径则默认当前路径 二 . 内容检索:grep  &q ...

  9. VS快捷键小收集

    1. Ctrl-M-O 折叠所有方法      Ctrl-M-M 折叠或展开当前方法     Ctrl-M-L 展开所有方法 2. 行编辑(复制,剪切,删除,交换) 当你在光标停留行使用快捷键Ctrl ...

  10. ubuntu下源码方式安装php5.4

    一.安装前准备 下载php-5.4.13.tar.gz最新版本放到/user/src目录下 二.安装 因为在安装php过程中,会依赖安装很多库,为了不让你反复安装,建议按步骤操作 安装autoconf ...