AOJ 0118 Property Distribution 题解
来源:互联网 发布:wish黄钻产品怎么优化 编辑:程序博客网 时间:2024/05/16 16:10
题意大概就是判断区域的个数,同样的字符属于一个区域,问有多少个区域.
想起来以前一位老师给我讲的一道类似的题目...直接DFS求解,已经判断过的区域再用另一个字符填上即可.
#include<cstdio>#include<iostream>using namespace std;char tmap[1000][1000];int w,h;int ans;int dfs(int x,int y,char seed){if(x<0 || x>w || y>h || y<0) return 0;if(tmap[x][y]==0 ||seed != tmap[x][y]) return 0;tmap[x][y] = 0;dfs(x,y-1,seed);dfs(x-1,y,seed);dfs(x+1,y,seed);dfs(x,y+1,seed);return 1;}int main(void){while(1){cin>>w>>h;if(h==0 && w==0) break;for(int i = 1;i<=w;i++){for(int j = 1;j<=h;j++){cin>>tmap[i][j];}}for(int i = 1;i<=w;i++){for(int j = 1;j<=h;j++){char seed = tmap[i][j];if(dfs(i,j,seed)==1) ans++;}}cout<<ans<<endl;ans = 0;}return 0;}
0 0
- AOJ 0118 Property Distribution 题解
- AOJ--0118 Property Distribution
- AOJ 0118 Property Distribution (DFS)
- AOJ 0118 Property Distribution (BFS)
- [DFS] AOJ 0118 Property Distribution
- Aoj 0118 Property Distribution【dfs】
- AOJ 0118 Property Distribution 【DFS】
- aizu/aoj-0118-Property Distribution
- [挑战程序设计竞赛] AOJ 0118 - Property Distribution
- AOJ 0118 Property Distribution (dfs)
- AOJ 0118 Property Distribution {深度优先搜索}
- AOJ 0118 Property Distribution (果园分类)
- Property Distribution(AOJ 0118)深度优先搜索
- AOJ 0118: Property Distribution (简单DFS)
- AOJ Property Distribution (dfs_连通性)
- AOJ 0033 ball+AOH 0118Property Distribution (DFS)
- AOJ 0118 Property Distribution(dfs 求连通块)
- Aizu-0118 Property Distribution
- mysql分区功能详细介绍,以及实例
- 工具与学习计划
- c# + sql procedure 实现分页
- Subsets I
- sockaddr与sockaddr_in结构体简介
- AOJ 0118 Property Distribution 题解
- Android开发者必知的开发资源
- Ajax+jquery 的前后台交互学习
- R语言与机器学习学习笔记(分类算法)(1)K-近邻算法
- MD5加密 Base64加密和解密算法 java
- eclipse里找不到com.sun.image.codec.jpeg.JPEGCodecimport与JPEGImageEncoder包和 import sun.misc.BASE64...
- 约瑟夫问题
- Tools
- ubuntu命令行连无线网