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 ...
随机推荐
- Navicat for mysql远程连接数据库详(1130错误解决方法)
用Navicat for mysql连接数据库测试下连接 如果出现1130错误错误代码是1130,ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to ...
- js调用asp.net 后台属性值
后台代码: public string title = "js调用后台属性值"; public void getContent() { return title; } 前台代码: ...
- 简单的NHibernate学习笔记
NHibernate是.NET平台下的ORM框架,与ADO.NET一样实现项目中数据库与项目系统的交互. .首先要用NHibernate框架就要有第三方的dll库来作为支持,附上百度云下载地址:(链接 ...
- Javascript的websocket的使用方法
javascript websocket接口 web实现客户端和服务端双向发送消息的方法有: 轮询,客户端定期向服务端请求: 长轮询,客户端定期向服务端请求,服务端只有有信息发送的时候才返回respo ...
- 【jsp+jpa】Check your ViewResolver setup!
困扰了好几天的坑 javax.servlet.ServletException: Circular view path [fileupload]: would dispatch back to the ...
- Automotive Security的一些资料和心得(3):Vehicular Security技术
1. Overview 1.1. Secure Hardware Extension (SHE) 基本结构:ECU里面有一块单独的Secure Zone.Secure Zone里面是SHE模块.SHE ...
- WCF 服务器已拒绝客户端凭据
将 WCF 服务器和客户端分别部署到不同机器上,可能会触发如下异常. 未处理 System.ServiceModel.Security.SecurityNegotiationException M ...
- javascript 冒泡
http://www.cnblogs.com/hh54188/archive/2012/02/08/2343357.html http://blog.csdn.net/xuefeng0707/arti ...
- Spring+MyBatis实践—登录和权限控制
1.实现用户登录功能: 通过session来实现用户登录功能.在用户登录时,将用户的相关信息放在HttpSession对象用,其中HttpSession对象可以通过HttpServletRequest ...
- php和.net的DES加密解密方法
.net版本 /// <summary> /// DES加密 /// </summary> /// <param name="pToEncrypt"& ...