forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5267f26
commit 381497f
Showing
1 changed file
with
5 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
BFS/2503.Maximum-Number-of-Points-From-Grid-Queries/Readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### 2503.Maximum-Number-of-Points-From-Grid-Queries | ||
|
||
根据题意,如果query越小,那么我们能够扩展的范围越小。query越大,扩展的范围是单调地增大的。所以我们必然会将queries排序,优先处理更小的query,比如常规的BFS来遍历所有小于query的格子;然后再处理更大的query,尝试重复利用已经探索过的网格区域。 | ||
|
||
此时,我们就发现此题很像`778.Swim-in-Rising-Water `,一开始只能在一个较矮的水平面游泳。后来水平面提升了,必然可以淹过一些在边界处相对地势较低的格子,不断往外溢出。于是,我们只要在BFS的时候,将队列里将格子按照地势从低到高排列。如果队列首元素的海拔小于query,那么它就确认被淹了,它的邻接格子就会成为新的堤岸被加入队列做下一步的考察。直至队列的首元素大于等于query,就意味着我们BFS的进程中被当前的边界所围住,已经占据了从左上角开始可以联络到的所有小于query的位置。 |