AOJ0118(DFS)
来源:互联网 发布:苏州php招聘 编辑:程序博客网 时间:2024/05/22 06:38
题意:求连通块的个数
分析:dfs标记连续的相同块就可以了
收获:dfs
AC:
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;char s[105][105];//int dx[4]={ -1, 1,0, 0 };//int dy[4]={ 0, 0, -1, 1 };int ma[4][2] ={ { 0, 1 }, { 0 , -1 }, { -1 , 0}, { 1 , 0 },};//int ma[4][2]= {{0,1},{0,-1},{-1,0},{0,1}};char ch ;int m,n;void dfs(int x,int y,char tree){ s[x][y]='1'; for(int i=0; i<4; i++) { int xn=x+ma[i][0],yn=y+ma[i][1]; if(xn>=0&&xn<m&&yn>=0&&yn<n) { if(s[xn][yn]==tree) { dfs(xn,yn,tree);// cout << xn <<" "<<yn<<endl; } } }}int main (){ while(cin >> m >> n&&m&&n) { for(int i=0; i<m; i++) { for(int j=0; j<n; j++) { cin >> s[i][j]; } } int sum=0; for(int i=0; i<m; i++) { for(int j=0; j<n; j++) { if(s[i][j]!='1') {// ch=s[i][j]; dfs(i,j,s[i][j]); sum++;// cout << i <<" "<< j<<endl; } } }// for(int i=0; i<m; i++)// {// for(int j=0; j<n; j++)// {// cout <<s[i][j]<<" ";// }// cout << endl;// } cout << sum <<endl; } return 0;}
0 0
- AOJ0118(DFS)
- aoj0118 Property Distribution(dfs)
- AOj0118 dfs
- AOJ0118 Property Distribution【DFS】
- AOJ0118 Property Distribution(DFS)
- AOJ0118 Property Distribution 裸dfs
- aoj0118 Property Distribution 暴力dfs
- AOJ0118——Property Distribution(DFS)
- aoj0118结题报告(太简单了,就不说明了)
- AOJ0118 Property Distribution 搜索
- aoj0118-Property Distribution
- 【暑假复习】【搜索】AOJ0118:Property Distribution
- HDU 4090 GemAnd Prince (DFS+BFS)/(DFS+DFS)
- (一般)POJ-2718 DFS套DFS
- pku 1011(dfs)
- poj1321(dfs)
- 1691(dfs + 回溯)
- 【hdu】Zipper (dfs)
- 每天一个 Linux 命令(5):rm 命令
- Python-元组-上了枷锁的列表
- 语言学习之通用法则
- Js中this与prototype
- php中const和define的区别
- AOJ0118(DFS)
- 算法——比较高级的数据结构“树”
- 简述数据库系统
- vector的内存分配机制分析
- 关于CSS中hover失效的几个原因
- mysql主从复制
- Javascript 代码优化
- Java内省introspector
- cf 540-C. Ice Cave