当前位置:网站首页>引爆炸弹(DFS)
引爆炸弹(DFS)
2022-04-23 01:21:00 【OldLeft】



样例输入
5 5
00010
00010
01001
10001
01000
样例输出
2
题解
遍历每一个炸弹,同时把它所在的行和列的炸弹不断递归引爆,并将该炸弹变为0
代码
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
char mp[1005][1005];
bool vis1[1005],vis2[1005];
void dfs(int x,int y){
mp[x][y]='0';
if(!vis1[x]){
vis1[x]=true;
for(int i=0;i<m;i++){
if(mp[x][i]=='1')
dfs(x,i);
}
}
if(!vis2[y]){
vis2[y]=true;
for(int i=0;i<n;i++){
if(mp[i][y]=='1')
dfs(i,y);
}
}
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>mp[i];
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(mp[i][j]=='1'){
ans++;
dfs(i,j);
}
}
}
cout<<ans<<endl;
return 0;
}
版权声明
本文为[OldLeft]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43833610/article/details/115740357
边栏推荐
- Examples of branch and loop statements
- engine.POST()处理POST请求
- [interview skills] how to face an interview without a leading group
- Optical cat super account password, reset optical cat to obtain super account password
- Ampere computing releases the computing power of observation cloud "core" and jointly promotes the development of observability
- What is October 24th? Why are there no senior programmers in China in their fifties and sixties, while foreigners,,, Yu Nianyu Hui take you to celebrate the 1024 programmer Festival
- App uses the template message from WeChat official account for message push.
- From thinking to practice, digital transformation is the successful path of it operation
- Let's talk about ruby
- Tdengine deployment cluster installation
猜你喜欢

Project manager's thinking mode worth trying: project success equation

Application of safe electricity management platform in Jingbian Museum safe electricity management system

gin--hello

Research and application of power monitoring system in sports training center

Im instant messaging development how to design a database that can support millions of concurrent users

Function encapsulation such as addition, deletion, modification and query of linked list (summary)

JD side: comment un thread enfant obtient - il la valeur de threadlocal du thread parent? Je suis couvert...

tdengine集群安装部署

Design and application of intelligent lighting control system in hospital

IMX6ULL裸机开发之EPIT周期性定时器分析及配置过程
随机推荐
深入解析Linux下的磁盘缓存机制与SSD的写入放大问题
Oplg: new generation cloud primary observable best practices
留给给5月的文章
那些咸鱼上买来的代码|ssm酒店客房管理系统|买来的源码是否真的可以使用|来自程序员的困惑|玉念聿辉|大丑村吴明辉
员工公寓楼建设项目电力监控系统的研究与应用
Learning of gin framework -- golang
天梯赛L2-6 树的遍历
Application of acrel-3200 remote prepaid electric energy management system in Fuzhou Wanbao Industrial Park
App uses the template message from WeChat official account for message push.
Interview eight part essay (disorderly order, no classification)
【Android工程师与智能家居产品的第一次接触③】SmartConfig一键配网在硬件端的具体实现|ESP8266一键配网在Arduino的具体实现|玉念聿辉
Huawei CDN is fast everywhere
Acrel-5000型建筑能耗监测系统在西咸空港花园项目的研究与应用
Gbase 8s检查点简介
IMX6ULL裸机开发之硬件IIC分析及配置过程
Redis forgets the password and resets the password
京东一面:子线程如何获取父线程 ThreadLocal 的值?我蒙了。。。
体育训练中心项目电力监控系统的研究与应用
GPT general timer analysis and configuration process of imx6ull bare metal development
Small example of gin - get request 1-handle handles get requests