水题,dfs

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
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;
}

lightoj 1012的更多相关文章

  1. LightOJ 1012 简单bfs,水

    1.LightOJ 1012  Guilty Prince  简单bfs 2.总结:水 题意:迷宫,求有多少位置可去 #include<iostream> #include<cstr ...

  2. Guilty Prince LightOJ - 1012

    Guilty Prince LightOJ - 1012 #include<cstdio> #include<cstring> ][]; int ans,h,w,T,TT; ] ...

  3. Lightoj 1012 - Guilty Prince

    bfs遍历一遍就行了. /* *********************************************** Author :guanjun Created Time :2016/6/ ...

  4. LightOJ 1012.Guilty Prince-DFS

    Guilty Prince  Time Limit: 2 second(s) Memory Limit: 32 MB Once there was a king named Akbar. He had ...

  5. LightOJ 1341 唯一分解定理

    Aladdin and the Flying Carpet Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld &a ...

  6. LightOJ 13361336 - Sigma Function (找规律 + 唯一分解定理)

    http://lightoj.com/volume_showproblem.php?problem=1336 Sigma Function Time Limit:2000MS     Memory L ...

  7. LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...

  8. lightoj刷题日记

    提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...

  9. Aladdin and the Flying Carpet (LightOJ - 1341)【简单数论】【算术基本定理】【分解质因数】

    Aladdin and the Flying Carpet (LightOJ - 1341)[简单数论][算术基本定理][分解质因数](未完成) 标签:入门讲座题解 数论 题目描述 It's said ...

随机推荐

  1. Linux之CentOS下vsftp安装及配置相关操作

    1.安装ftps——vsftpd: #yum install vsftpd 2.指定上传下载目录配置: 如:用户名:xxx,需指定目录:/xxx/xxx #useradd -d /xxx/xxx -s ...

  2. thinkphp 文件上传

    form表单中 enctype="multipart/form-data" public function upload()    {      import('ORG.Net.U ...

  3. android通过泛型获取控件或视图

    @SuppressWarnings("unchecked") public <T extends Fragment> T getFragment(int id) { T ...

  4. start-stop-daemon 命令

    Usage: start-stop-daemon [<option> ...] <command> Commands: -S|–start — <argument> ...

  5. 细说PHP中strlen和mb_strlen的区别

    在PHP中,strlen与mb_strlen是求字符串长度的函数,但是对于一些初学者来说,如果不看手册,也许不太清楚其中的区别.下面通过例子,讲解这两者之间的区别. $str='中文a字1符'; ec ...

  6. python引入导入自定义模块和外部文件

    参考:http://blog.csdn.net/devil_2009/article/details/15816237 项目中想使用以前的代码,或者什么样的需求致使你需要导入外部的包 如果是web 下 ...

  7. 1-了解Python

    为什么使用python: 软件质量: 可读写.一致性.软件质量 支持软件开发的高级重用机制 提供开发者的效率: 代码只有java或C++的1/5~1/3 无须编译链接,提高了程序原的效率 程序的可移植 ...

  8. rman全备份异机恢复

    一.测试环境 [oracle@localhost ~]$ uname -a Linux localhost.localdomain -.el6.x86_64 # SMP Tue May :: EDT ...

  9. javascript高级编程笔记01(基本概念)

    1.在html中使用JavaScript 1.  <script> 元素 <script>定义了下列6个属性: async:可选,异步下载外部脚本文件. charset:可选, ...

  10. <一> SQL 基础

    删除数据库 drop database database-name 创建新表格 create table tablename (col1 type1 [not null] [primary key], ...