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 ...
随机推荐
- SQL获取数据库中表的列名和列类型
select column_name as [字段名],data_type as [数据类型] from information_schema.columns where table_name='表名 ...
- bootstrap table 行号 显示行号 添加行号 bootstrap-table 行号
思想:借助bootstrap-table 本身的index属性, 巧妙的的通过formatter 实现 { field: 'Number', title: 'Number', formatter: f ...
- 【InstallShield】 为什么卸载后有的文件没有删掉
1.Component的属性Permanent设置为Yes. 2.Component的ID为空. 3.Component被其他应用程序或者Feature使用. 4.设置了一个Condition,在安装 ...
- NFS挂载及写入故障
最近在做架构时,分离出来一台图片服务器,图片服务器是通过NFS(网络文件系统)给两台web服务器提供图片存储的,在编辑NFS配置文件(/etc/exports)时:想了一下,允许访问NFS共享目录的范 ...
- python AES 加密与解密
#用aes加密,再用base64 encode def aes_encrypt(data): from Crypto.Cipher import AES import base64 key=setti ...
- 关于Mysql数据库longblob格式数据的插入com.mysql.jdbc.PreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V问题分析
当数据库字段为blob类型时 ,我们如果使用PreparedStatement中的setBinaryStream(int,InputStream,int)方法需要注意 在向blob字段类型中插入数据时 ...
- 【Hades】ades是一个开源库,基于JPA和Spring构建,通过减少开发工作量显著的改进了数据访问层的实现
几乎每个应用系统都需要通过访问数据来完成工作.要想使用领域设计方法,你就需要为实体类定义和构建资源库来实现领域对象的持久化.目前开发人员经常使用JPA来实现持久化库.JPA让持久化变得非常容易,但是仍 ...
- VS调试错误:“没有可用于当前位置的源代码”的解决方案
今天,有朋友在问为什么我在调试的时候会出现"没有可用于当前位置的源代码"的错误呢? MSDN上的说法:没有可用于当前位置的源代码,项目不包含您试图查看代码的源代码.原因通常是双击了 ...
- 关于http客户端常见错误"警告:Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is rec"
在开发过程中,经常得写http客户端测试接口服务,今天在使用过程中出现了这样的一个警告: 警告: Going to buffer response body of large or unknown s ...
- delphi xe5 android 控制蓝牙
本文部分内容摘自: http://www.pclviewer.com/android/用以下代码中的接口实现控制蓝牙的开.关及详细信息 unit Androidapi.JNI.BluetoothAda ...