v4t3564
The Binding of Isaac
Ok, now I will introduce this game to you…
Isaac is trapped in a maze which has many common rooms…
Like this…There are 9 common rooms on the map.
And there is only one super-secret room. We can’t see it on the map. The super-secret room always has many special items in it. Isaac wants to find it but he doesn’t know where it is.Bob
tells him that the super-secret room is located in an empty place which is adjacent to only one common rooms.
Two rooms are called adjacent only if they share an edge. But there will be many possible places.
Now Isaac wants you to help him to find how many places may be the super-secret room.
Input
Multiple test cases. The first line contains an integer T (T<=3000), indicating the number of test case.
Each test case begins with a line containing two integers N and M (N<=100, M<=100) indicating the number
of rows and columns. N lines follow, “#” represent a common room. “.” represent an empty place.Common rooms
maybe not connect. Don’t worry, Isaac can teleport.
Output
One line per case. The number of places which may be the super-secret room.
Sample
Input
Copy2
5 3
…#
.##
##.
.##
##.
1 1
Output
Copy8
4
遍历每个小方格;边上的单独遍历,只要是#就加一;里面的要判定上下左右有多少个#。
#include <bits/stdc++.h>
using namespace std;
int t,n,m,i,j,a[120][120];
int fun(int i,int j)
{
int k=0;
if(a[i-1][j]==1)
k++;
if(a[i][j-1]==1)
k++;
if(a[i+1][j]==1)
k++;
if(a[i][j+1]==1)
k++;
if(k==1)
return 1;
else
return 0;
}
int main()
{
char c;
scanf("%d",&t);
while(t--)
{
memset(a,0,sizeof(a));
scanf("%d%d",&n,&m);
getchar();
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
{
scanf("%c",&c);
if(c=='.')
a[i][j]=0;
else if(c=='#')
a[i][j]=1;
}
getchar();
}
int cnt=0;
for(i=1; i<=n; i++)
{
if(a[i][1])
cnt++;
if(a[i][m])
cnt++;
}
for(j=1; j<=m; j++)
{
if(a[1][j])
cnt++;
if(a[n][j])
cnt++;
}
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
{
if(a[i][j]==0)
{
if(fun(i,j))
cnt++;
}
}
}
cout<<cnt<<'\n';
}
return 0;
}
- 剑指OFFER之重建二叉树(九度OJ1385)
- 记录visual Studio使用过程中的两个问题
- 剑指OFFER之二维数组中的查找(九度OJ1384)
- Python标准库02 时间与日期 (time, datetime包)
- PR&AE插件开发遇到的一个坑
- 一个简单的inno setup模板
- Python标准库——走马观花
- 共享栈
- inno setup读取注册表遇到的一个坑
- Python标准库的学习准备
- Python小题目 针对快速教程
- [Oracle入门级]知识概况
- Space Nation 创始人卡尔•瓦哈加可拉:AI为人类探索太空提供了更多可能
- Final Cut Pro X效果插件开发总结
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- python六十四课——高阶函数练习题(二)
- python六十四课——高阶函数练习题(三)
- Jenkins+Maven+Svn实现代码自动打包与发布
- python六十五课——单元测试(一)
- python六十六课——单元测试(二)
- Linux企业生产常见问题集合(一)答案
- python六十八课——网络编程之UDP协议
- python六十九课——网络编程之TCP协议
- Linux扩容分区操作过程
- python第七十课——python2与python3的一些区别
- Linux运维必会的100道MySql面试题之(一)
- Linux运维必会的100道MySql面试题之(二)
- Apache服务的反向代理及负载均衡配置
- Linux系统集群架构线上项目配置实战(二)
- Linux系统集群架构线上项目配置实战(三)