热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

poj2482StarsinYourWindow

DescriptionFleetingtimedoesnotblurmymemoryofyou.Canitreallybe4yearssinceIfirstsawyou?Istil

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

题意就是在一个直角坐标系中有n个星星,给出每个点的坐标和权值,求用w×h的举行能圈住的星星的权值总和最大是多少,矩形边界上的星星不算。
因为矩形大小确定,所以每个矩形可以由它任意一个顶点确定,不妨用它右上角的点
那么对每个星星来说,能覆盖它的矩形的右上角的点一定在以它为左下角的w×h的矩形内,在两个区域的重叠处的矩形可以覆盖这两个星星
问题就变成了在平面上有若干个区域,每个区域有一个权值,求在哪个坐标上区域权值和最大
矩形边界上的星星不算,故我们将每个星星的坐标从(x,y)变成(x-0.5,y-0,5),同时让矩形的顶点都是整数,因此能覆盖这个星星的矩形的左下角是(x,y),右上角是(x+w-1,y+h-1),边界上的星星也算在内
然后扫描线即可

线段树维护每个点被覆盖多少次
每次查询的都是1-n的最大值所以不需要pushdown也就不用打标记了

//#include
#include
#include
#include
#include
#include
#define ll long long
using namespace std;
const int N=1e5+10;
int n,cnt;
ll w,h;
struct orz{
ll x,l,r;
int c;}a[N];
ll X[N],sum[N*4],mx[N*4];
bool cmp(orz a,orz b)
{
if (a.x==b.x) return a.c return a.x}
void update(int s,int l,int r,int L,int R,int val)
{
if (L<=l&&r<=R)
{
sum[s]+=val;
mx[s]+=val;
return;
}
int mid=(l+r)>>1;
if (L<=mid) update(s<<1,l,mid,L,R,val);
if (R>mid) update(s<<1|1,mid+1,r,L,R,val);
mx[s]=max(mx[s<<1],mx[s<<1|1])+sum[s];
}
int main()
{
while (scanf("%d%lld%lld",&n,&w,&h)!=EOF)
{
cnt=0;
memset(mx,0,sizeof(mx));
memset(sum,0,sizeof(sum));
ll x,y; int c;
for (int i=1;i<=n;i++)
{
scanf("%lld%lld%d",&x,&y,&c);
a[++cnt].x=x;
a[cnt].l=y; a[cnt].r=y+h-1; a[cnt].c=c; X[cnt]=a[cnt].l;
a[++cnt].x=x+w;
a[cnt].l=y; a[cnt].r=y+h-1; a[cnt].c=-c;X[cnt]=a[cnt].r;
}
sort(a+1,a+1+cnt,cmp);
sort(X+1,X+1+cnt);
int base=unique(X+1,X+1+cnt)-X-1;
ll ans=0;
for (int i=1;i<=cnt;i++)
{
int l=lower_bound(X+1,X+1+base,a[i].l)-X;
int r=lower_bound(X+1,X+1+base,a[i].r)-X;
update(1,1,base,l,r,a[i].c);
ans=max(ans,mx[1]);
}
printf("%lld\n",ans);
}
return 0;
}
View Code

 


推荐阅读
author-avatar
丁可丁可_136
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有