博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
lightoj 1012
阅读量:6955 次
发布时间:2019-06-27

本文共 1106 字,大约阅读时间需要 3 分钟。

水题,dfs

#include
#include
#include
#include
#include
using namespace std;const int MAXN = 22;int W, H;char str[MAXN][MAXN], vis[MAXN][MAXN];int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};bool inMap(int x, int y){ return x >= 0 && x < H && y >= 0 && y < W;}void dfs(int x, int y){ vis[x][y] = 1; for(int i = 0;i < 4;i ++){ int xx = dir[i][0] + x, yy = dir[i][1] + y; if(inMap(xx, yy) && !vis[xx][yy] && str[xx][yy] == '.') dfs(xx, yy); }}int main(){ int t,x,y,CASE(0); scanf("%d", &t); while(t--){ scanf("%d%d", &W, &H); for(int i = 0;i < H;i ++){ scanf("%s", str[i]); for(int j = 0;j < W;j ++) { if(str[i][j] == '@') x = i, y = j; } } memset(vis, 0, sizeof vis); int ans = 0; dfs(x, y); for(int i = 0;i < H;i ++) for(int j = 0;j < W;j ++) ans += vis[i][j]; printf("Case %d: %d\n", ++CASE, ans); } return 0;}

转载于:https://www.cnblogs.com/wangzhili/p/3950245.html

你可能感兴趣的文章
Tomcat部署记事
查看>>
λ(lambda)表达式
查看>>
[MySQL TroubleShooting] 服务启动报错
查看>>
斑马技术邀您吃生鲜——以极速物流方案让您领鲜一步
查看>>
[转载]Windows网络编程系列教程之四:Select模型
查看>>
Linux系统目录结构
查看>>
一键系统维护工具 v 1.9
查看>>
第十一单元练习
查看>>
变量替换删除企业应用场景
查看>>
nautilus can't be used now,due to an unexpected error解决方法
查看>>
XenApp/XenDesktop 7.11新功能
查看>>
全面降低windows系统的安全隐患(一)[Web安全大家谈]
查看>>
2014年7月14日学习笔记--scriptreplay相关操作
查看>>
openstack resize 中遇到的问题
查看>>
AD-删除账户命令 Remove-ADUser
查看>>
第九单元练习题
查看>>
scponly 密钥无密码scp登录
查看>>
重置otrs登录密码
查看>>
CentOS下搭建SVN服务器
查看>>
#15、#16 网络的基本构成与网络的几协议
查看>>