POJ2482 Stars in Your Window 题解】的更多相关文章

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…
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…
Stars in Your Window Language:Default Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15036 Accepted: 4061 Description Fleeting time does not blur my memory of you. Can it really be 4 years since I first saw you? I sti…
题面 Poj 题解 下面内容引用自"李煜东 <算法竞赛进阶指南>"(对原文略有缩减,侵删): 因为矩形的大小固定,所以矩形可以由它的任意一个顶点唯一确定.我们可以考虑把矩形的右上角顶点放在什么位置,圈住的星星亮度总和最大. 所以,对于一颗星星,能够覆盖住这颗星星的右上角的位置在区间\([x,y]-[x+w,y+h]\)之间,但是由于边界上的星星不算,所以不妨将星星变为\([x-0.5,y-0.5]\),于是右上角变为\([x+w-1,y+h-1]\). 问题就转化成了:平面…
此题可用线段树或静态二叉树来做. 考虑用线段树: 很容易想到先限定矩形横轴范围再考虑在此纵轴上矩形内物品总价值的最大值. 那么枚举矩形横轴的复杂度是O(n)的,考虑如何快速获取纵轴上的最大值. 我们不可能再次枚举纵轴,依次统计,这样做事多余的. 考虑窗口在纵轴上的滑动,每上升到一个新的高度,在加入新元素的同时只需将最底层的那些值弹出队列即可. 这样我们需要考虑队列上元素和的最大值. 我们从反面考虑每个元素对特定队列(矩形纵轴位置)的贡献. 枚举窗口的上面一条边,那么元素对窗口贡献正值当且仅当H(…
[POJ2482]Stars in Your Window 题面 vjudge 题解 第一眼还真没发现这题居然™是个扫描线 令点的坐标为\((x,y)\)权值为\(c\),则 若这个点能对结果有\(c\)的贡献,必须要矩形左下角的点的范围必须在\(([x,x+w),[y,y+h))\)之间 则按扫描线套路将一个类似矩形的范围拆成线\((x,y1,y2,c)\).\((x+w,y1,y2,-c)\)(依次表示横坐标.下端点纵坐标.上端点纵坐标.权值)即可 最后注意排序时不但要按\(x\)排,也要按…
Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11706   Accepted: 3183 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 beaut…
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 classroo…
Stars in Your Window   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 walk…
题目连接 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…
1208 Stars in Your Window 题目来源: Poj 基准时间限制:2 秒 空间限制:131072 KB 分值: 160 难度:6级算法题  收藏  取消关注 整点上有N颗星星,每颗星星有一个亮度.用一个平行于x轴和y轴,宽为W高为H的方框去套星星.套住的所有星星的亮度之和为S(包括边框上的星星),求S的最大值. Input 第1行:共3个数N, W, H,中间用空格分割,N为星星的数量,W为方框的宽度,H为方框的高度.(2 <= N <= 50000, 1 <= W,…
POJ 2823 Sliding  Window 题解 Description An array of size n ≤ 106 is given to you. There is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the slidi…
id=2482" target="_blank" style="">题目链接:poj 2482 Stars in Your Window 题目大意:平面上有N个星星.问一个W∗H的矩形最多能括进多少个星星. 解题思路:扫描线的变形.仅仅要以每一个点为左上角.建立矩形,这个矩形即为框框左下角放的位置能够括到该点,那么N个星星就有N个矩形,扫描线处理哪些位置覆盖次数最多. #include <cstdio> #include <cstr…
Description 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. T…
POJ 2482 Stars in Your Window 题目链接 题意:给定一些星星,每一个星星都有一个亮度.如今要用w * h的矩形去框星星,问最大能框的亮度是多少 思路:转化为扫描线的问题,每一个星星转化为一个矩形,那么等于求矩形相交区域值最大的区域,利用线段树去维护就可以 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long…
[poj P2482] Stars in Your Window Time Limit: 1000MS  Memory Limit: 65536K 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…
Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13196   Accepted: 3609 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 beaut…
[POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11294   Accepted: 3091 Description Fleeting time does not blur my memory of you. Can it really be 4 years since I first saw you? I still remembe…
题意:在二维坐标系中有一些带权值的点,要求用一个长宽指定不能互换的框套住其中的一些,使得它们的权值和最大. n<=10000 x,y<=2^31 思路:首先按X排序,将Y坐标离散化,X坐标用扫描线框定,每个点(x,y)在x中只对y有a[i]的贡献,y+h有-a[i]的贡献,线段树(树状数组更好写)维护最大子段和即可. ..]of record l,r,s,m:int64; end; x,y,c,a,h:..]of int64; n,m,i,j,tt,ww,up,w1,h1:longint; a…
题面: An array of size n ≤ 106 is given to you. There is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves rightwards by one po…
[题目链接] http://poj.org/problem?id=2482 [题目大意] 给出一些点的二维坐标和权值,求用一个长H,宽W的矩形能框住的最大权值之和, 在矩形边缘的点不计算在内 [题解] 我们计算能扫到这个点的区间范围,将其拆分为两条平行于y轴的左闭右开的直线, 为方便边界处理,我们将坐标扩大两倍,之后我们按照x轴对这些线段进行扫描 统计出现的最大值即可. [代码] #include <cstdio> #include <algorithm> #include <…
遇见poj上最浪漫的题目..题目里图片以上几百词为一篇模板级英文情书.这情感和细腻的文笔深深地打动了我..不会写情书的童鞋速度进来学习.传送门 题意:坐标系内有n个星星,每个星星都有一个亮度c (1<= c <= 100),坐标和亮度都已给出. 有一个矩形的窗户(就是个理想化的矩形),四条边与x轴或y轴平行.矩形可以在坐标系内平移,但不可以进行旋转操作.求这个矩形可以框住的星星的亮度之和最大为多少.注意:恰好在边上的星星不算在内. 思路:好吧,这题又是看别人的题解才做出来的,深深自责中...思…
题目链接:http://poj.org/problem?id=2482 读完题干不免有些心酸(…
http://poj.org/problem?id=2482 线段树扫描线 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N = 20003; int in() { int k = 0, fh = 1; char c = getchar(); for(; c < '0' || c > '9'; c = getchar()) if (c…
该题和 黑书 P102 采矿 类似 参考链接:http://blog.csdn.net/shiqi_614/article/details/7819232http://blog.csdn.net/tsaid/article/details/6686907http://www.cnblogs.com/372465774y/archive/2012/07/28/2613272.html 题意: 给你10000以内的星星的坐标和星星的亮度(即分别为x,y,c),要求用W*H的矩形去围住一个区域, 使得…
线段树+离散化+扫描线 AC之后,又认真读了一遍题目,好文章. #include<cstdio> #include<map> #include<algorithm> using namespace std; +; int n; long long W,H; long long x[maxn],y[maxn],v[maxn]; struct seg { long long X; long long Y1,Y2; long long val; }s[*maxn]; stru…
原地址:http://poj.org/problem?id=2482 神题,被誉为最浪漫的题目,一位acmer以自己独特的方式写下的殷殷情语 你窗前的星星 纵时光飞逝如梭,也我对你的回忆也永不黯然.从第一次见面以来,也许已经有四年之久了.但是,我记得,我清晰地记得,四年前的那一天,那一幕,那一抹阳光,那一弯微笑,它们如同刻刀一般,在我心中留下了如此清晰的印记. 四年前,在美丽的珠海校园,在无意间,我瞥见了你的含笑的背影.命运牵引着我的视线向你而去.你轻轻地跨过班级的大门,当你纤细的手抚过门框的那…
题目大意: 求一个窗体覆盖最多的星星的权值. 思路分析: 每个星星看成 左下点为x y 右上点为x+w-1 y+h-1 的矩形. 然后求出最大覆盖的和. #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #define lson num<<1,s,mid #define rson num<<1|1,mid+1,e #define…
如果按一般的思路来想,去求窗户能框住的星星,就很难想出来. 如果换一个思路,找出每颗星星能被哪些窗户框住,这题就变得非常简单了. 不妨以每个窗户的中心代表每个窗户,那么每颗星星所对应的窗户的范围即以其为中心的.W*H的矩形.把这些矩形的左边和右边,分别加上和减去其价值.而统计这些边只需要开一个线段树统计即可,用每次加边后得到的最大值更新答案. 需要注意的是,计算这些边上两点的坐标时可能出现0.5的情况,为了避免,把原坐标*2即可.而且坐标过大,需要离散化. 一开始打的时候,竟然,错了样例.仔细看…
这题开始一直被矩形框束缚了,想法一直都是枚举线,但是这样枚举都需要O(n^2)...但是看了别人的思路,感觉这题思想真心很好(PS:开头好浪漫的描述啊,可惜并没有什么用)  题意就是在平面上给你一些星星,一定是整数点,每颗星星有一个亮度,然后给你一个固定大小只能移动不能旋转的矩形框,问你任意移动矩形框最多可以将星星的最大的亮度装进框内,注意框边上的星星不计算 以前做过有个类似的题,但是数据范围小又很水,因为可以枚举每个点作为四个角分别统计就过了.可是这样是错的,因为可能有情况是四个点分别限制矩形…