HDU--1241 简单DFS
来源:互联网 发布:mimo软件 编辑:程序博客网 时间:2024/05/16 18:28
题目链接:点击打开链接
遍历整个图,把‘@’变成‘*’,统计次数
AC代码:
#include<iostream>#include<cstring>#include<cstdio>#include<queue>#include<algorithm>using namespace std;typedef long long ll;const int N=1000;struct Node{ int x; int y;};int n,m;#define MM(x,y) memset(x,y,sizeof(x))queue<Node>Q;int vis[N][N];char mp[N][N];int dir[8][2]={{0,1},{0,-1},{1,0},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};void dfs(int x,int y){ int i; Node now,next; now.x=x; now.y=y; MM(vis,0); vis[x][y]=1; Q.push(now); while(!Q.empty()) { now=Q.front(); Q.pop(); for(i=0;i<8;i++) { int tx=now.x+dir[i][0]; int ty=now.y+dir[i][1]; if(tx>=1&&tx<=n&&ty>=1&&ty<=m&&!vis[tx][ty]&&mp[tx][ty]=='@') { next.x=tx; next.y=ty; vis[tx][ty]=1; mp[tx][ty]='*'; Q.push(next); } } }}int main(){ int i,j; while(cin>>n>>m&&n&&m) { MM(mp,0); int res=0; for(i=1;i<=n;i++) { cin>>mp[i]+1; } for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { if(mp[i][j]=='@') { mp[i][j]='*'; while(!Q.empty()) { Q.pop(); } dfs(i,j); res++; } } } cout<<res<<endl; } return 0;}
阅读全文
0 0
- hdu 1241 简单dfs
- HDU--1241 简单DFS
- HDU 1241 简单的DFS
- hdu 1241 Oil Deposits 简单dfs
- hdu 1241 简单 搜索DFS (深搜)
- HDU-1213(简单DFS)
- hdu 2660 简单 dfs
- hdu 3274 简单 dfs
- hdu 3290 (简单dfs)
- 搜索--HDU简单DFS
- HDU 1181(简单dfs)
- HDU 1016 超简单DFS
- HDU 3368 Reversi (简单dfs)
- HDU/HDOJ 1016 简单dfs
- HDU-5546(简单DFS)
- hdu 题目1241 Oil Deposits(简单DFS)
- HDU 1241 DFS
- hdu 1241 DFS
- Numeric Keypad
- CSS清除浮动的五种方式
- 前端笔记
- 机房重构---单例模式应用
- 【Linux基础】Linux的5种IO模型详解
- HDU--1241 简单DFS
- 自定义view之viewpager的使用
- Caffe学习(2):在Ubuntu下运行手写体数字教程
- NumPy的详细教程
- java中大数用法
- 经久不衰的CSDN
- 上下滚动公告
- 安装redis
- Spring Boot学习记录(二)--thymeleaf模板