当前位置:网站首页>130. surrounding area
130. surrounding area
2022-06-24 18:33:00 【One star accompanies the moon】
Power button 2020/8/11 Punch in topic
This topic is similar to the maze , If you can't get to the boundary of the map , Mark all possible routes , If you can reach the border, you don't have to deal with it . This is obviously a search (dfs and bfs All right )
O Representative channel ,X Representative wall
If you do a pop search, most of the time TLE, The size of the graph is unknown . It must be very slow to judge point by point , It's a question , Go to the border , That's the point , We can start from the boundary , Then you just need to start with all the boundaries , Mark all the paths that can be reached !
class Solution {
public:
int dx[4]={
1,0,-1,0};
int dy[4]={
0,1,0,-1};
int row,col;
void dfs(vector<vector<char>>& board,int x,int y){
if(x<0||x>=row||y<0||y>=col||board[x][y]!='O') return;
board[x][y]='Y';
for(int i=0;i<4;i++){
int xx=x+dx[i];
int yy=y+dy[i];
dfs(board,xx,yy);
}
}
void solve(vector<vector<char>>& board) {
row=board.size();
if(row==0) return;
col=board[0].size();
if(col==0) return;
for(int i=0;i<row;i++){
dfs(board,i,0);
dfs(board,i,col-1);
}
for(int i=1;i<col-1;i++){
dfs(board,0,i);
dfs(board,row-1,i);
}
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
if(board[i][j]=='Y') board[i][j]='O';
else board[i][j]='X';
}
}
}
};
边栏推荐
- Sword finger offer 10- ii Frog jumping on steps
- Ten excellent business process automation tools for small businesses
- It is often blocked by R & D and operation? You need to master the 8 steps before realizing the requirements
- Application service access configuration parameters
- 布隆过滤器综述文章论文阅读:Optimizing Bloom Filter: Challenges, Solutions, and Comparisons
- Seven strategies for successfully integrating digital transformation
- 如何在 R 中使用 Fisher 的最小显着性差异 (LSD)
- 电子元器件行业B2B电商市场模式、交易能力数字化趋势分析
- 你知道CMDB吗?
- What makes data analysts good- Cassie Kozyrkov
猜你喜欢

Specification for self test requirements of program developers

2022 network security C module of the secondary vocational group scans the script of the surviving target aircraft (municipal, provincial and national)

Overall planning and construction method of digital transformation

The country has made a move! Launch network security review on HowNet

Nacos cluster starts throwing set of SQL_ SELECT_ LIMIT is not support
[North Asia data recovery]_ mdb_ catalog. Mongodb database data recovery case in case of WT file corruption
About swagger

It is often blocked by R & D and operation? You need to master the 8 steps before realizing the requirements

Exception: Gradle task assembleDebug failed with exit code 1

【leetcode】838. Push domino (Analog)
随机推荐
Two micro service interviews where small companies suffer losses
Software testing methods: a short guide to quality assurance (QA) models
Easyplayer streaming media player plays HLS video. Technical optimization of slow starting speed
电子元器件行业B2B电商市场模式、交易能力数字化趋势分析
Leetcode topic [array] -46- full arrangement
It is often blocked by R & D and operation? You need to master the 8 steps before realizing the requirements
EasyCVR国标协议接入的通道,在线通道部分播放异常是什么原因?
SAP license:sap s/4hana is the answer
SAP license: ERP for supply chain management and Implementation
Crmeb multi merchant PC packaging tutorial
How do yaml files and zmail collide with the spark of the framework, and how can code and data be separated gracefully?
The country has made a move! Launch network security review on HowNet
Issue 39: MySQL time class partition write SQL considerations
TCE入围2020年工信部信创典型解决方案
Sword finger offer 10- ii Frog jumping on steps
Complete Guide to web application penetration testing
TCE was shortlisted as a typical solution for ICT innovation of the Ministry of industry and information technology in 2020
How to select the best test cases for automation?
SAP license: what is ERP supply chain
Gateway solves cross domain access