题目名称:The Binding of Isaac
题目链接: http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/3564.html
题意简述:
这道题目的主要意思是:“#”代表一个房间 “.”代表空白区域。求super-secret room。这个super-secret room是它的上下左右只能与一个“#”间相连。图很大,并不限于所给你的行列。
简略解析:
有两种方法,第一种是按照“#”间的个数;第二种是按照空白区域的个数。
我用的是第一种,进行了用数字表示,将“#”上下左右都加1,最后找出来,含有1的个数
第二种:
用字符来做的。
https://blog.csdn.net/zcmu_2024/article/details/81189938
代码:
注意:用字符的话,回车和空格也会默认为字符,要抛弃掉。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int lab[110][110];
int main(){
int t;
scanf("%d",&t);
while(t--){
memset(lab,0,sizeof(lab));
int a,b;
char c;
scanf("%d %d%*c",&a,&b);
for(int i=1;i<=a;i++){
for(int j=1;j<=b;j++){
scanf("%c",&c);
if(c=='#'){
lab[i][j]=5;
lab[i-1][j]++;
lab[i+1][j]++;
lab[i][j-1]++;
lab[i][j+1]++;
}
}
scanf("%*c");
}
int x=0;
for(int i=0;i<=a+1;i++){
for(int j=0;j<=b+1;j++){
if(lab[i][j]==1){
x++;
}
}
}
printf("%d\n",x);
}
return 0;
}