hdu 1241
来源:互联网 发布:数值型数据的分组方法 编辑:程序博客网 时间:2024/05/17 03:24
简单的广搜题目,一次AC.
#include <iostream>#include <cstdio>#include <cstring>#include <queue>using namespace std;struct node{ int x,y;};const int maxn = 105;char map[maxn][maxn];bool vis[maxn][maxn];int row,col;int dir[8][2]={{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1}};void bfs(int r, int c){ queue<node> que; node t,s; vis[r][c] = true; s.x = r , s.y = c; que.push(s); while(!que.empty()){ t = que.front(); que.pop(); for(int i = 0; i < 8; ++i){ s.x = t.x + dir[i][0]; s.y = t.y + dir[i][1]; if(s.x >= 0 && s.x < row && s.y >= 0 && s.y < col && !vis[s.x][s.y] && map[s.x][s.y]=='@'){ vis[s.x][s.y] = true; que.push(s); } } }}int main(){ while(~scanf("%d %d",&row,&col) && row && col){ int ans = 0; for(int i = 0; i < row; ++i) scanf("%s",map[i]); //for(int i = 0; i < row; ++i) // printf("%s\n",map[i]); memset(vis,false,sizeof(vis)); for(int i = 0; i < row; ++i) for(int j = 0; j< col; ++j) if(map[i][j] == '@' && !vis[i][j]){ // cout<<i<<" "<<j<<endl; bfs( i, j); ans++; } printf("%d\n",ans); } return 0;}
- hdu 1241
- HDU 1241
- hdu 1241
- hdu 1241
- hdu 1241
- hdu 1241
- hdu-1241
- hdu 1241
- hdu 1241
- HDU 1241
- hdu 1241
- hdu-1241
- hdu 1241
- HDU(1241)
- hdu 1241
- Hdu 1241
- hdu 1241
- HDU 1241
- sqlite时间戳处理
- 借助百度地图api下载公交信息
- 更新Subclipse 1.8x出错
- Log4j 2.0 使用说明
- webservice的几种开发方式总结
- hdu 1241
- c++推荐看的一些经典书籍
- [oracle]共享服务器模式下processes参数是否限制连接数
- linux 无密码登录配置里的注意事项
- Bugzilla安装和编辑所遇到的问题
- android_asset URI详细使用方法
- Andrid中的Looper,Handler,Message研究
- oracle中bulk collect into用法
- 机房收费系统总结