【暑假复习】【搜索】AOJ0118:Property Distribution
来源:互联网 发布:武汉软件新城发展前景 编辑:程序博客网 时间:2024/06/05 11:40
题意
有三种符号,同种符号四联通,求连通块总数
题解
枚举每一个点,若未被访问过,就访问这个点所在的连通块,将整个连通块的点全部标记,总数++
#include<cstdio>#include<cstring>#include<algorithm>#define SF scanf#define PF printf#define MAXN 110using namespace std;int w[4][2]={{1,0},{0,-1},{-1,0},{0,1}};int col[MAXN][MAXN],vis[MAXN][MAXN],n,m,cnt;char c;bool check(int x,int y){ if(x*y==0||x>n||y>m) return 0; if(vis[x][y]==1) return 0; return 1;}void dfs(int x,int y){ vis[x][y]=1; for(int i=0;i<4;i++){ int x1=x+w[i][0]; int y1=y+w[i][1]; if(check(x1,y1)&&col[x1][y1]==col[x][y]) dfs(x1,y1); }}int main(){ SF("%d%d",&n,&m); while(n*m!=0){ memset(col,0,sizeof col); memset(vis,0,sizeof vis); cnt=0; for(int i=1;i<=n;i++){ SF("\n"); for(int j=1;j<=m;j++){ SF("%c",&c); if(c=='@') col[i][j]=1; else if(c=='#') col[i][j]=2; else col[i][j]=3; } } for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(vis[i][j]==0){ cnt++; dfs(i,j); } PF("%d\n",cnt); SF("%d%d",&n,&m); }}
阅读全文
0 0
- 【暑假复习】【搜索】AOJ0118:Property Distribution
- AOJ0118 Property Distribution 搜索
- aoj0118-Property Distribution
- AOJ0118 Property Distribution【DFS】
- AOJ0118 Property Distribution(DFS)
- AOJ0118 Property Distribution 裸dfs
- aoj0118 Property Distribution(dfs)
- aoj0118 Property Distribution 暴力dfs
- AOJ0118——Property Distribution(DFS)
- 【暑假复习】【搜索】POJ1979RedandBlack
- AOJ 0118 Property Distribution {深度优先搜索}
- Property Distribution(AOJ 0118)深度优先搜索
- 【暑假复习】【搜索】AOJ0033:Ball
- 【暑假复习】【搜索】AOJ0558:Cheese
- 【暑假复习】【搜索】POJ3009:Curling 2.0
- 【暑假复习】【搜索】POJ3187:Backward Digit Sums
- Aizu-0118 Property Distribution
- AOJ--0118 Property Distribution
- 从零开始学贪心算法
- es6特性实践
- Linux Kernel 调度实现 -----欣赏
- New Surface pro +Vmware 12 +Ubuntu 16.04 分辨率问题
- HDU1698 Just a Hook(成段更新)【模板】
- 【暑假复习】【搜索】AOJ0118:Property Distribution
- 神经网络Loss损失函数总结
- 软件开发文档-详细设计文档
- Linux下创建DB2数据库
- Windows 用cmd命令行下载git上资料
- EJB体系结构之EJB容器
- Android系统源代码的下载与编译
- kubeadm安装kubernetes(canal)
- 微信小程序wx.request后台数据交互