HDU2952 DFS
来源:互联网 发布:android仿淘宝头条 编辑:程序博客网 时间:2024/05/22 17:16
题目省略
题意:求四连块个数
解题思路:很水的DFS。。。
代码如下
#include <queue>#include <stdio.h>#include <memory.h>#include <stdio.h>#include <iostream>using namespace std;#define maxn 1005char pic[maxn][maxn];int flag[maxn][maxn];int n,m;void dfs(int r,int s,int num){ if(r<0||r>=n||s<0||s>=m) return; if(pic[r][s]=='.'||flag[r][s]) return; flag[r][s]=num; dfs(r+1,s,num); dfs(r-1,s,num); dfs(r,s+1,num); dfs(r,s-1,num);}int main(){ //freopen("in.txt","r",stdin); int t; cin>>t; while(t--) { cin>>n>>m; getchar(); for(int i=0; i<n; i++) gets(pic[i]); memset(flag,0,sizeof(flag)); int num=0; for(int i=0; i<n; i++) for(int j=0; j<m; j++) if(pic[i][j]=='#'&&flag[i][j]==0) dfs(i,j,++num); printf("%d\n",num); } return 0;}
阅读全文
0 0
- HDU2952 DFS
- HDU2952:Counting Sheep(DFS)
- hdu2952(DFS Counting Sheep )
- HDU2952:Counting Sheep(DFS)
- HDU2952 Counting Sheep (DFS)
- HDU2952:Counting Sheep(DFS)
- HDU2952 Counting Sheep (DFS)
- HDU2952 (DFS) Counting Sheep
- hdu2952
- 模板题-----DFS深度搜索 HDU2952
- hdu2952——Counting Sheep(DFS&&BFS)
- HDU2952 ( Counting Sheep )
- HDU2952(深度搜索)
- HDU2952:Counting Sheep(BFS)
- HDU2952 Counting Sheep
- hdu2952之搜索
- HDU2952:Counting Sheep(BFS)
- hdu2952 Counting Sheep
- c内存管理学习总结
- python错误和异常处理
- js 创建对象的几种常用的方式
- scikit-learn中的SVM使用指南
- scrollview嵌套recycleView相关问题
- HDU2952 DFS
- python参数化-数组
- Android Studion 快速定位内存泄露的方法
- android系统架构图及各层介绍
- Hibernate和JPA之间的联系
- Eclipse常见错误 (Tomcat)
- vscode中利用git通过ssh连接github
- 数据结构基础【03】单链表
- OracleDataGuard部署