lightoj 1012
水题,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的更多相关文章
- LightOJ 1012 简单bfs,水
1.LightOJ 1012 Guilty Prince 简单bfs 2.总结:水 题意:迷宫,求有多少位置可去 #include<iostream> #include<cstr ...
- Guilty Prince LightOJ - 1012
Guilty Prince LightOJ - 1012 #include<cstdio> #include<cstring> ][]; int ans,h,w,T,TT; ] ...
- Lightoj 1012 - Guilty Prince
bfs遍历一遍就行了. /* *********************************************** Author :guanjun Created Time :2016/6/ ...
- 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 ...
- LightOJ 1341 唯一分解定理
Aladdin and the Flying Carpet Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld &a ...
- LightOJ 13361336 - Sigma Function (找规律 + 唯一分解定理)
http://lightoj.com/volume_showproblem.php?problem=1336 Sigma Function Time Limit:2000MS Memory L ...
- LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...
- lightoj刷题日记
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...
- Aladdin and the Flying Carpet (LightOJ - 1341)【简单数论】【算术基本定理】【分解质因数】
Aladdin and the Flying Carpet (LightOJ - 1341)[简单数论][算术基本定理][分解质因数](未完成) 标签:入门讲座题解 数论 题目描述 It's said ...
随机推荐
- 解决VS2008打开假死或者打开设计模式假死的问题
我昨天刚装完OFFICE 2010一直也没重启,vs2008是可以使用的.今早来到办公室,打开工程发现开了半天VS2008一般空白,查看应用程序显示正在运行,再查看进程发现里面多一个setup.exe ...
- 如何使用 require.js ,实现js文件的异步加载,避免网页失去响应,管理模块之间的依赖性,便于代码的编写和维护。
一.为什么要用require.js? 最早的时候,所有Javascript代码都写在一个文件里面,只要加载这一个文件就够了.后来,代码越来越多,一个文件不够了,必须分成多个文件,依次加载.下面的网页代 ...
- win7 64 安装Oracle 11G 、使用PLSQL进行连接 标准实践
第一步: 安装oracle 服务,两个解压包,分别解压后 合并到一个文件夹,点击exe安装 (安装过程中如遇到PATH问题,直接忽略即可) 第二步:使用SQLPlus 测试是否成功 安装成功:CMD ...
- 【2】认识Bootstrap
作为当下最流行的前端开发框架Bootstrap,它可大大简化网站开发过程,从而深受广大开发者的喜欢,当然你去它的官网中文网站就能看到大大的小标定义:“简洁.直观.强悍.移动设备优先的前端开发框架,让w ...
- 【InstallShield】 为什么卸载后有的文件没有删掉
1.Component的属性Permanent设置为Yes. 2.Component的ID为空. 3.Component被其他应用程序或者Feature使用. 4.设置了一个Condition,在安装 ...
- Python和C++交互
关键字:Python 2.7,VS 2010,swig OS:Win8.1 with update. 1.下载swig:http://www.swig.org/download.html 2.将swi ...
- DOS下删除整个目录及下属所有文件夹及文件最好用的命令
Windows XP以上的版本,在使用DOS命令模式下删除目录(目录就是档案总管中所谓的资料夹)不是用 deltree,而是用 rmdir 指令. 在Windows XP.2000.NT下都可用rmd ...
- JavaScript闭包底层解析
1. 闭包是一个函数,这个函数有权访问另一个函数作用域中的变量,创建闭包最常见的方式,就是在函数内部创建函数.要想彻底搞清其中细节,必须从函数从创建到调用的时候都发生了什么入手 2. 函数第一次被调用 ...
- win7(x64)+VS2012+cocos2d-x环境的配置以及试运行
原地址:http://blog.csdn.net/gf771115/article/details/20740993 转自:http://blog.sina.com.cn/s/blog_62df697 ...
- Java程序发展之路