当前位置:网站首页>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';
}
}
}
};
边栏推荐
- Skills of writing test cases efficiently
- It is often blocked by R & D and operation? You need to master the 8 steps before realizing the requirements
- 腾讯云TCS:面向应用的一站式PaaS 平台
- 你知道CMDB吗?
- Ultimate Guide: comprehensive analysis of log analysis architecture of Enterprise Cloud native PAAS platform
- Architecture decryption from distributed to microservice: several common microservice architecture schemes
- R language Quantitative Ecology redundancy analysis RDA analysis plant diversity species data visualization
- SAP license: SAP s/4 Hana module function introduction
- Redis learning -- list of redis operations
- Rapidssl getting started SSL certificate
猜你喜欢

Considerations for it project demand analysis

How to start cloud native application development

Network security database penetration of secondary vocational group in 2022

On software requirement analysis
[golang] leetcode intermediate - jumping game & different paths

SAP license:sap s/4hana is the answer
Ultimate Guide: comprehensive analysis of log analysis architecture of Enterprise Cloud native PAAS platform

The country has made a move! Launch network security review on HowNet
congratulate! The first dragon lizard community annual outstanding contribution award is announced. Check it now
What if the database table structure changes? Smartbi products support one click synchronization
随机推荐
Do you know CMDB?
Application service access configuration parameters
Nine practical guidelines for improving responsive design testing
Some knowledge of the beginning of 2022
视频平台如何将旧数据库导入到新数据库?
Failure analysis | database failure MHA is not switched
717.1-bit and 2-bit characters [sliding window]
Leetcode question 136 [single number]
Tencent cloud TCS: an application-oriented one-stop PAAS platform
Vite+web3:报错出现ReferenceError: process is not defined
What is business intelligence (BI)?
RestCloud ETL抽取动态库表数据实践
Analysis on the issue of raising the right of MSSQL in 2021 secondary vocational group network security competition in Shandong Province
Easyplayer streaming media player plays HLS video. Technical optimization of slow starting speed
Data driven decision making: Decision intelligence and design thinking
Common MySQL commands of installation free version
Overall planning and construction method of digital transformation
Keep two decimal places
Bigdecimalavoiddoubleconstructorrule: do not directly use the double variable as a parameter to construct BigDecimal
Redpacketframe and openmode packages