跳到正文

13970067326a

912999

吃饱喝好,一路走好

在洛谷打开
资料、奖项与版本

资料

编号
912999
抓取
C++
#include <bits/stdc++.h>

using namespace std;
int ans,n,m;
string a[110];
int dx[5]={-1,1,0,0};
int dy[5]={0,0,-1,1};
void dfs(int x,int y){
    a[x][y]='0';
    int fx,fy;
    for(int i=0;i<=3;i++){
            fx=x+dx[i];
            fy=y+dy[i];
            if(fx>=0&&fx<n&&fy>=0&&fy<m&&a[fx][fy] > '0'){
                dfs(fx,fy);
            }
        } 
        return ;
    }
    
 
int main(){
  scanf("%d%d",&n,&m);
	for (int i = 0; i < n; i++){
	cin >> a[i];
}
for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			if (a[i][j] > '0'){
					dfs(i,j);
				ans++;
			}
		}
	}
 printf("%d",ans);
	
	return 0;
}
RP++
RP++
RP++
RP++
https://www.luogu.com.cn/paste/tah77ok9


111001111011110110010111111001001011110010011111111001101011011010011011
https://acm.hdu.edu.cn/
杭电网址

https://www.luogu.com.cn/article/7lborgqn

https://www.easychat.work/#/chat

共 2 篇
  1. 个人记录

    dfs速成指南

    本文主要介绍了深度优先搜索(DFS)的核心概念与应用,内容分为两部分: 取数问题:涵盖从基础枚举到进阶的选数问题,重点讲解如何利用标记数组、剪枝及回溯(状态复原)优化排列组合搜索,避免重复计算。 二维图遍历:以海战为例,说明在网格搜索中需标记已访问路径,防止因走回头路导致无限递归或超时(TLE)。 文章结合代码实例解析了关键逻辑,并鼓励读者通过勤加练习彻底掌握 DFS。

  2. 个人记录

    模拟赛总结

    T1 刚开始以为是线段树 发现非常难实现 容易写挂 期望分数:? 只需要认真看题就可以发现一些性质 其实是非常简单的模拟 当小于60 时才需要遍历 否则直接输出 “big” 期望 :100 pts