山东省第七届ACM省赛------The Binding of Isaac
2016-06-10 21:49
232 查看
The Binding of Isaac
Time Limit: 2000MS Memory limit: 65536K
题目描述
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.
输入
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.
输出
One line per case. The number of places which may be the super-secret room.
示例输入
2 5 3 ..# .## ##. .## ##. 1 1 #
示例输出
8 4
来源
“浪潮杯”山东省第七届ACM大学生程序设计竞赛
题意
题目虽然看起来很长,但是只要读懂它就非常简单啦~说的是给你一个地图,’.‘代表空地,‘#’代表门,求在地图中某个非‘#’的点所相邻的上下左右总共有一个‘#’的位置有多少个。
我们可以将整个地图保持在一个字符二维数组中,然后在输入的时候向右向下分别偏移一个单位,因为地图外的一周也要检测啦~
然后枚举所有不是‘#’的点便可以了,反正不会超时,最后输出结果~
AC代码:
#include"stdio.h" #include"string.h" #include<iostream> using namespace std; char a[105][105]; int main() { int n; cin>>n; while(n--) { int c,b; cin>>c>>b; getchar(); memset(a,0,sizeof(a)); for(int i=1; i<=c; i++) gets(a[i]+1); int s=0; for(int i=0; i<=c+1; i++) for(int j=0; j<=b+1; j++) if(a[i][j]!='#') { int d=0; if(i>0&&a[i-1][j]=='#')d++; if(a[i+1][j]=='#')d++; if(j>0&&a[i][j-1]=='#')d++; if(a[i][j+1]=='#')d++; if(d==1)s++; } printf("%d\n",s); } return 0; }
相关文章推荐
- solr 4.7.2 环境搭建(比较齐全的参考)
- 项目:程序填空
- C语言选择排序详解及其实现
- QT绘制半透明窗体(改写paintEvent,超级简单)
- .net 4.0 之后的协变与逆变
- C++解压zip文件
- 如何设计一个 iOS 控件?(iOS 控件完全解析)
- PHP笔记10-day14
- Linux 备忘录
- 在windows下的QT编程中的_TCHAR与QString之间的转换
- mac 下安装securecrt
- 《程序员修炼之道--从小工到专家》阅读笔记02
- HTML5中canvas画图之画矩形和矩形掏空
- 数书九章 原序
- C++11中的std::bind
- sql 行列转换
- 一段程序代码 --- 实现解析字典,自动转换生成属性。
- hdu 1452(因子和+积性函数)
- QT 遍历目录查找指定文件(比较简单)
- PHP笔记9-day13