Stars in Your Window(线段树求最大矩形交)
题目连接
http://poj.org/problem?id=2482
Description
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
Sample Input
1 2 3
2 3 2
6 3 1
3 5 4
1 2 3
2 3 2
5 3 1
Sample Output
6
HINT
将点转化成矩形。
题意
给你一个w*h的矩形,和N个点,每个点都有一个权值,然后你用这个矩形去圈住他们,然后问你矩形所能圈住的最大权值是多少?
记得是多测哦。
题解:
代码:
//#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(线段树求最大矩形交)的更多相关文章
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- 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 ...
- POJ 2482 Stars in Your Window 线段树
如果按一般的思路来想,去求窗户能框住的星星,就很难想出来. 如果换一个思路,找出每颗星星能被哪些窗户框住,这题就变得非常简单了. 不妨以每个窗户的中心代表每个窗户,那么每颗星星所对应的窗户的范围即以其 ...
- POJ 2482 Stars in Your Window (线段树区间合并+扫描线)
这题开始一直被矩形框束缚了,想法一直都是枚举线,但是这样枚举都需要O(n^2)...但是看了别人的思路,感觉这题思想真心很好(PS:开头好浪漫的描述啊,可惜并没有什么用) 题意就是在平面上给你一些星 ...
- poj2823Sliding Window(线段树求最值)
链接 裸线段树 这题时间卡的挺棒 #include <iostream> #include<cstdio> #include<cstring> #include&l ...
- POJ 2482 Stars in Your Window(线段树+扫描线)
题目链接 非常不容易的一道题,把每个点向右上构造一个矩形,将问题转化为重合矩形那个亮度最大,注意LL,注意排序. #include <cstdio> #include <cstrin ...
- POJ 2823 Sliding Window 线段树区间求和问题
题目链接 线段树区间求和问题,维护一个最大值一个最小值即可,线段树要用C++交才能过. 注意这道题不是求三个数的最大值最小值,是求k个的. 本题数据量较大,不能用N建树,用n建树. 还有一种做法是单调 ...
- 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)
原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...
- UVA 11983 Weird Advertisement --线段树求矩形问题
题意:给出n个矩形,求矩形中被覆盖K次以上的面积的和. 解法:整体与求矩形面积并差不多,不过在更新pushup改变len的时候,要有一层循环,来更新tree[rt].len[i],其中tree[rt] ...
随机推荐
- 1096 Consecutive Factors
题意: 给出一个正整数N,找到最长的连续的可分解因子.如N=630,可被分解为630=3*5*6*7,其中5*6*7是3个连续的因子. 思路: 首先,需要明确,对于任何一个整数,如果它是素数,则不可被 ...
- 1117 Eddington Number
题意:给出了N个数字,确定一个尽可能大的数字E,要求这N个数字中大于E的数字有E个. 思路: 乍一看不知道题目在说啥.静下心来多读几遍题目,在草稿纸上比划比划,发现是个大水题.解释一下样例,原始序列为 ...
- 张瀚荣:如何用UE4制作3D动作游戏
转自:http://www.gamelook.com.cn/2015/06/218267 GameLook报道/ 6月5日,2015年第三期GameLook开放日‧虚幻引擎专场活动在上海正式举行,此次 ...
- 我是怎么用python模仿勒索软件加密文件的(病毒)
前言: 今天下午上学,用python写个勒索脚本然后打包成exe是个不错的选择 我们来搞事情吧.看那学校我就不想上学. 0x01:要用到的模块,各位请自行准备 import win32api,win3 ...
- webRTC peerconnection_client demo创建VS工程
编译了webRTC Windows源码之后,想使用编译出来的库写一个demo出来,但是又不知到怎么下手.就想通过源码中带的示例peerconnection_client和peerconnection_ ...
- Coins and Queries(codeforce 1003D)
Polycarp has nn coins, the value of the i-th coin is aiai . It is guaranteed that all the values are ...
- Linux的基本指令--服务器
ftp: 1.安装vsftpd服务器 sudo apt-get install vsftpd 2.创建一个空目录,供用户上传:创建服务器文件夹,ftp服务器,服务器端和客户端,我建立的是/home/c ...
- 为cscope查找列表增添色彩
我在使用cscope的时候,偏好于不用quickfix窗口来显示查找列表,而是选择类似ctag的列表.但这会带来一个比较麻烦的问题,就是窗口列表一片白色,看起来非常难受: 特别是当搜索结果特别多的时候 ...
- 【总结整理】如何判断伪需求(摘自pmcafe)
1.客户不会直接提需求,都是给解决方案,所以得到用户的反馈之后,先反推一下是很必要的,为什么客户会有这样的方案 总结:方案不合适 例如:客户只会说我要快马,反推一下,其实客户是想要更快,这样的话,解决 ...
- Linux3基本命令 ls,pwd,cat,echo,mv,cp,mkdir,rm,ln
ls 列出文件名称. -l 列出长文件名称. -rwxr-xr-- 1 root root 10739 Dec 23 13:31 bbscon (7) (4) (5) (6) ...