
Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
History is littered with hundreds of conflicts over the future of a community, group, location or business that were "resolved" when one of the parties stepped ahead and destroyed what was there. With the original point of contention destroyed, the debates would fall to the wayside. Archive Team believes that by duplicated condemned data, the conversation and debate can continue, as well as the richness and insight gained by keeping the materials. Our projects have ranged in size from a single volunteer downloading the data to a small-but-critical site, to over 100 volunteers stepping forward to acquire terabytes of user-created data to save for future generations.
The main site for Archive Team is at archiveteam.org and contains up to the date information on various projects, manifestos, plans and walkthroughs.
This collection contains the output of many Archive Team projects, both ongoing and completed. Thanks to the generous providing of disk space by the Internet Archive, multi-terabyte datasets can be made available, as well as in use by the Wayback Machine, providing a path back to lost websites and work.
Our collection has grown to the point of having sub-collections for the type of data we acquire. If you are seeking to browse the contents of these collections, the Wayback Machine is the best first stop. Otherwise, you are free to dig into the stacks to see what you may find.
The Archive Team Panic Downloads are full pulldowns of currently extant websites, meant to serve as emergency backups for needed sites that are in danger of closing, or which will be missed dearly if suddenly lost due to hard drive crashes or server failures.
You are given a
grid
of sizeN x N
, and each cell of this grid has a lamp that is initially turned off.You are also given an array of lamp positions
lamps
, wherelamps[i] = [rowi, coli]
indicates that the lamp atgrid[rowi][coli]
is turned on. When a lamp is turned on, it illuminates its cell and all other cells in the same row, column, or diagonal.Finally, you are given a query array
queries
, wherequeries[i] = [rowi, coli]
. For theith
query, determine whethergrid[rowi][coli]
is illuminated or not. After answering theith
query, turn off the lamp atgrid[rowi][coli]
and its 8 adjacent lamps if they exist. A lamp is adjacent if its cell shares either a side or corner withgrid[rowi][coli]
.Return an array of integers
ans
,* whereans[i]
should be1
if the lamp in theith
query was illuminated, or0
if the lamp was not.*Example 1:
Example 2:
Example 3:
Constraints:
1 <= N <= 109
0 <= lamps.length <= 20000
lamps[i].length == 2
0 <= lamps[i][j] < N
0 <= queries.length <= 20000
queries[i].length == 2
0 <= queries[i][j] < N
这道题给了一个
NxN
的格子,说是每个位置都有一个台灯,初始时都是熄灭的,现在给了一个二维数组 lamps,是一些开着的台灯的位置,说是每个开着的台灯都可以照亮该台灯所在的行,列,对角线,和逆对角线上所有的位置。现在又给了一个 queries 数组,是一系列的位置,问该位置是否被照亮,并且说得到结果之后,要关上该位置即周围八个相邻位置上所有开着的台灯。这里的台灯实际上跟国际象棋中的皇后是一样的,之前也做过N皇后问题 N-Queens,所以我们知道如何判断任意两个位置放皇后是否冲突,正好也就是这里的判断某位置是否会被照亮。博主最开始想到的方法是,先把所有亮着的台灯放到一个 TreeSet 中,然后遍历所有 query,对于每个位置,遍历所有的亮着的台灯,调用N皇后中的判断冲突的方法,就可以知道该位置是否被照亮,然后再将其和周围8个相邻位置的亮着的台灯关上,但是很不幸,这种方法超时 TLE 了,所以需要进一步的优化。上面的方法主要耗时的地方在于遍历每个台灯,并且判断能否照到 query 位置,当亮着的台灯非常的多的时候,就会非常耗时间。想办法用些更巧妙的方法,这里可以统计每行,每列,每条对角线,以及逆对角线上亮着的灯的个数,用 HashMap 分别建立映射,只要映射值大于0,则对应位置上一定会被照亮。台灯的横纵坐标分别映射行和列,横纵坐标之差映射对角线,横纵坐标之和映射逆对角线,然后还有一个 TreeSet 用来保存亮着的台灯的坐标。然后遍历所有 query,利用该 query 的横纵坐标去上述4个 HashMap 中找,只要任意一个映射值大于0,则该位置就是被照亮的。然后遍历该位置以及周围八个相邻的位置,若有亮着的台灯,将所有 HashMap 的映射值自减1,并且移出 TreeSet 即可,参见代码如下:Github 同步地址:
#1001
类似题目:
N-Queens
N-Queens II
参考资料:
https://leetcode.com/problems/grid-illumination/
https://leetcode.com/problems/grid-illumination/discuss/242898/C%2B%2B-with-picture-similar-to-N-Queens
https://leetcode.com/problems/grid-illumination/discuss/243076/Java-Clean-Code-O(N)-Time-and-O(N)-Space-Beats-100
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: