1001. Grid Illumination
There is a 2D grid of size n x n where each cell of this grid has a lamp that is initially turned off.
You are given a 2D array of lamp positions lamps, where lamps[i] = [rowi, coli] indicates that the lamp at grid[rowi][coli] is turned on. Even if the same lamp is listed more than once, it is turned on.
When a lamp is turned on, it illuminates its cell and all other cells in the same row, column, or diagonal.
You are also given another 2D array queries, where queries[j] = [rowj, colj]. For the jth query, determine whether grid[rowj][colj] is illuminated or not. After answering the jth query, turn off the lamp at grid[rowj][colj] and its 8 adjacent lamps if they exist. A lamp is adjacent if its cell shares either a side or corner with grid[rowj][colj].
Return an array of integers ans, where ans[j] should be 1 if the cell in the jth query was illuminated, or 0 if the lamp was not.
解题要点:
1. 每个点(lamp)对应四条线,判断query的点是否在这些线上。
2. 容易想到通过hashmap保存这些点,映射四条线。但是判断query的时候,时间复杂度为n2。
3. 所以通过hashmap保存四条线,进行计数统计。query在计数大于0的线上,值为1
4. 八个相邻lamp内,用-1到+2的双重循环构造坐标。如果有坐标在lamp集合内,移除坐标,线的计数减一。
There is a 2D grid of size n x n where each cell of this grid has a lamp that is initially turned off.
You are given a 2D array of lamp positions lamps, where lamps[i] = [rowi, coli] indicates that the lamp at grid[rowi][coli] is turned on. Even if the same lamp is listed more than once, it is turned on.
When a lamp is turned on, it illuminates its cell and all other cells in the same row, column, or diagonal.
You are also given another 2D array queries, where queries[j] = [rowj, colj]. For the jth query, determine whether grid[rowj][colj] is illuminated or not. After answering the jth query, turn off the lamp at grid[rowj][colj] and its 8 adjacent lamps if they exist. A lamp is adjacent if its cell shares either a side or corner with grid[rowj][colj].
Return an array of integers ans, where ans[j] should be 1 if the cell in the jth query was illuminated, or 0 if the lamp was not.
解题要点:
1. 每个点(lamp)对应四条线,判断query的点是否在这些线上。
2. 容易想到通过hashmap保存这些点,映射四条线。但是判断query的时候,时间复杂度为n2。
3. 所以通过hashmap保存四条线,进行计数统计。query在计数大于0的线上,值为1
4. 八个相邻lamp内,用-1到+2的双重循环构造坐标。如果有坐标在lamp集合内,移除坐标,线的计数减一。
1219. Path with Maximum Gold
In a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position, you can walk one step to the left, right, up, or down.
You can't visit the same cell more than once.
Never visit a cell with 0 gold.
You can start and stop collecting gold from any position in the grid that has some gold.
解题要点:
1. 回溯。枚举每个点作为起点,进行递归和回溯。
2. 规定了「每个单元格只能被开采一次」,因此当我们到达位置(x,y) 时,我们可以将 grid[x][y] 暂时置为 00;在进行回溯之前,再将 grid[x][y] 的值恢复
3. 全局变量保存黄金数量。
In a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position, you can walk one step to the left, right, up, or down.
You can't visit the same cell more than once.
Never visit a cell with 0 gold.
You can start and stop collecting gold from any position in the grid that has some gold.
解题要点:
1. 回溯。枚举每个点作为起点,进行递归和回溯。
2. 规定了「每个单元格只能被开采一次」,因此当我们到达位置(x,y) 时,我们可以将 grid[x][y] 暂时置为 00;在进行回溯之前,再将 grid[x][y] 的值恢复
3. 全局变量保存黄金数量。
今日#英语# #阅读# 分享——Millennium-old tomb restored in China's Shanxi中国山西修复的千年古墓
Source: XinhuaEditor: huaxia2021-12-27 21:02:30
TAIYUAN, Dec. 27 (Xinhua) -- An ancient tomb with rare murals dating back to the Tang Dynasty (618-907) has been restored in north China's Shanxi Province, according to the Taiyuan Northern Qi Dynasty Mural Museum.
The tomb was discovered in an elementary school in Taiyuan, capital of Shanxi, in 2019 and later moved to the museum for protection and restoration.
According to the epitaph, the tomb owner Guo Xing was a mid-ranking military officer in the Tang Dynasty. The roof, walls, coffin bed, corridors and the doors of the tomb were all decorated with exquisite murals.
Defects in the murals such as fissures, hollows and blemishes have been fixed, and the tomb will open to the public in the future, said the museum.
Interestingly, various figures in the mural paintings appear to be making "V" signs with their middle and index fingers.
The exquisite murals of the tomb reveal the noble status of the tomb owner and attest to its historical, artistic and scientific value, said Feng Gang, a researcher at the Taiyuan Institute of Cultural Relics Protection. Enditem
p1:Undated file photo provided by Taiyuan Institute of Cultural Relics Protection shows a part of restored murals of an ancient tomb dating back to the Tang Dynasty (618-907) in Taiyuan, north China's Shanxi Province. The tomb was discovered in an elementary school in Taiyuan, capital of Shanxi, in 2019 and later moved to the museum for protection and restoration.
Defects in the murals such as fissures, hollows and blemishes have been fixed, and the tomb will open to the public in the future, said the Taiyuan Northern Qi Dynasty Mural Museum.
Interestingly, various figures in the mural paintings appear to be making "V" signs with their middle and index fingers. (Taiyuan Institute of Cultural Relics Protection/Handout via Xinhua)
p2:Undated file photo provided by Taiyuan Institute of Cultural Relics Protection shows a part of restored murals of an ancient tomb dating back to the Tang Dynasty (618-907) in Taiyuan, north China's Shanxi Province. The tomb was discovered in an elementary school in Taiyuan, capital of Shanxi, in 2019 and later moved to the museum for protection and restoration.Defects in the murals such as fissures, hollows and blemishes have been fixed, and the tomb will open to the public in the future, said the Taiyuan Northern Qi Dynasty Mural Museum.Interestingly, various figures in the mural paintings appear to be making "V" signs with their middle and index fingers. (Taiyuan Institute of Cultural Relics Protection/Handout via Xinhua)
p3:Undated file photo provided by Taiyuan Institute of Cultural Relics Protection shows a part of restored murals of an ancient tomb dating back to the Tang Dynasty (618-907) in Taiyuan, north China's Shanxi Province. The tomb was discovered in an elementary school in Taiyuan, capital of Shanxi, in 2019 and later moved to the museum for protection and restoration.Defects in the murals such as fissures, hollows and blemishes have been fixed, and the tomb will open to the public in the future, said the Taiyuan Northern Qi Dynasty Mural Museum.Interestingly, various figures in the mural paintings appear to be making "V" signs with their middle and index fingers. (Taiyuan Institute of Cultural Relics Protection/Handout via Xinhua)
原文链接:https://t.cn/A6JvuP3n
来源:新华社
Source: XinhuaEditor: huaxia2021-12-27 21:02:30
TAIYUAN, Dec. 27 (Xinhua) -- An ancient tomb with rare murals dating back to the Tang Dynasty (618-907) has been restored in north China's Shanxi Province, according to the Taiyuan Northern Qi Dynasty Mural Museum.
The tomb was discovered in an elementary school in Taiyuan, capital of Shanxi, in 2019 and later moved to the museum for protection and restoration.
According to the epitaph, the tomb owner Guo Xing was a mid-ranking military officer in the Tang Dynasty. The roof, walls, coffin bed, corridors and the doors of the tomb were all decorated with exquisite murals.
Defects in the murals such as fissures, hollows and blemishes have been fixed, and the tomb will open to the public in the future, said the museum.
Interestingly, various figures in the mural paintings appear to be making "V" signs with their middle and index fingers.
The exquisite murals of the tomb reveal the noble status of the tomb owner and attest to its historical, artistic and scientific value, said Feng Gang, a researcher at the Taiyuan Institute of Cultural Relics Protection. Enditem
p1:Undated file photo provided by Taiyuan Institute of Cultural Relics Protection shows a part of restored murals of an ancient tomb dating back to the Tang Dynasty (618-907) in Taiyuan, north China's Shanxi Province. The tomb was discovered in an elementary school in Taiyuan, capital of Shanxi, in 2019 and later moved to the museum for protection and restoration.
Defects in the murals such as fissures, hollows and blemishes have been fixed, and the tomb will open to the public in the future, said the Taiyuan Northern Qi Dynasty Mural Museum.
Interestingly, various figures in the mural paintings appear to be making "V" signs with their middle and index fingers. (Taiyuan Institute of Cultural Relics Protection/Handout via Xinhua)
p2:Undated file photo provided by Taiyuan Institute of Cultural Relics Protection shows a part of restored murals of an ancient tomb dating back to the Tang Dynasty (618-907) in Taiyuan, north China's Shanxi Province. The tomb was discovered in an elementary school in Taiyuan, capital of Shanxi, in 2019 and later moved to the museum for protection and restoration.Defects in the murals such as fissures, hollows and blemishes have been fixed, and the tomb will open to the public in the future, said the Taiyuan Northern Qi Dynasty Mural Museum.Interestingly, various figures in the mural paintings appear to be making "V" signs with their middle and index fingers. (Taiyuan Institute of Cultural Relics Protection/Handout via Xinhua)
p3:Undated file photo provided by Taiyuan Institute of Cultural Relics Protection shows a part of restored murals of an ancient tomb dating back to the Tang Dynasty (618-907) in Taiyuan, north China's Shanxi Province. The tomb was discovered in an elementary school in Taiyuan, capital of Shanxi, in 2019 and later moved to the museum for protection and restoration.Defects in the murals such as fissures, hollows and blemishes have been fixed, and the tomb will open to the public in the future, said the Taiyuan Northern Qi Dynasty Mural Museum.Interestingly, various figures in the mural paintings appear to be making "V" signs with their middle and index fingers. (Taiyuan Institute of Cultural Relics Protection/Handout via Xinhua)
原文链接:https://t.cn/A6JvuP3n
来源:新华社
✋热门推荐