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 ...
随机推荐
- memcached全面剖析--5
memcached的应用和兼容程序 mixi案例研究 mixi在提供服务的初期阶段就使用了memcached. 随着网站访问量的急剧增加,单纯为数据库添加slave已无法满足需要,因此引入了memca ...
- 原创:Javascript Websocket客户端封装
调试中,马马虎虎能用var LeesWebSocket = function (options) { this.defaults = { host: "127.0.0.1", po ...
- 今年的IT大趋势是虚拟现实
从今年下半年开始,陆陆续续出现了一些基于虚拟现实技术的创业公司,先是从IT新闻中的一篇创业故事中了解到这个方向,后来再是身边一个以前的朋友也发布了类似的产品. 从他们的产品来看,基本都是围绕教育行业开 ...
- bug - colorWithPatternImage:
// 在ios5之前, 再通过以下方法设置背景时, 有闪屏bug self.view.backgroundColor = [UIColor colorWithPatternImage:<#(no ...
- linux删除某类型文件的命令
使用linux命令行,删除某目录下某类型的文件,如:删除.rar结尾的所有文件. 命令如下: find . -name "*.rar" -type f -print -exec r ...
- BZOJ 3901 棋盘游戏 解题报告
这题有个重要性质: 我们设 Flag[i][j] 表示 (i, j) 是否被奇数个操作所覆盖, 也就是操作次数对 2 取模. 设 x = (n + 1) / 2. 那么对于所有的合法的操作方案, 令 ...
- Bengio最新博文:深度学习展望
Bengio最新博文:深度学习展望 人类一直梦想着创造有智能的机器.早在第一台可编程计算机问世前100多年,发明家就对如何能让由连杆和齿轮组成的设备也变得更加智能这一命题充满好奇.后来,20世纪40年 ...
- 用 Maven 做项目构建
转自:http://www.ibm.com/developerworks/cn/java/j-lo-maven/index.html 本文将介绍基于 Apache Maven 3 的项目构建的基本概念 ...
- 1008: [HNOI2008]越狱
n个人,m种信仰: 问你相邻的人信仰不同的情况有多少种? 首先第一个人有m种选择,第二个人有m-1种选择,后面所有的人都只有m-1种选择: 所以结果就是m^n-m*(m-1)^(n-1) #inclu ...
- hdu 1423
最长公共上升子序列:O(n*m)的算法: #include<cstdio> #include<cstring> #define maxn 1000 using namespac ...