The Binding of ISAAC
Time limit:2000ms Memory limit:65536k
Title Description
Ok, now I'll introduce this game ...
Isaac are trapped in a maze which have many common rooms ...
Like this ... There is 9 common rooms on the map.
And there are only one super-secret. We can ' t see it on the map. The super-secret is always have 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 was located in a empty place which was adjacent to only one common rooms.
The rooms is called adjacent only if they share an edge. But there'll be many possible places.
Now ISAAC wants-to-help him-find how many places could be the super-secret. input
Multiple test cases. The first line contains a integer T (t<=3000), indicating the number of the test case.
Each test case begins with a line containing the integers N and M (n<=100, m<=100) indicating the number
of rows and columns. N lines follow, "#" represent a common. "." 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.
Sample Input
2
5 3
.. #
.##
##.
. ##
##.
1 1
#
Sample Output
8
4
Tips
Source"Wave Cup" Shandong Province Seventh annual ACM College Student Program Design contest
Sample Program
Commit status If there is a room up and down and only one ' # ' description is a special room ask such a room with a few direct perimeter plus a lap '. ' And then the violence will do Accode:
#include <bits/stdc++.h>
using namespace std;
Char dp[120][120];
int n,m,loop;
int main () {
scanf ("%d", &loop);
while (loop--) {
scanf ("%d%d", &n,&m);
memset (DP, '. ', sizeof (DP));
for (int i=1;i<=n;++i) for
(int j=1;j<=m;++j)
cin>>dp[i][j];
int ans=0;
for (int i=0;i<=n+1;++i) for
(int j=0;j<=m+1;++j) {
if (dp[i][j]== ' # ') continue;
int tmp=0;
if (dp[i+1][j]== ' # ') tmp++;
if (dp[i][j+1]== ' # ') tmp++;
if (dp[i][j-1]== ' # ') tmp++;
if (dp[i-1][j]== ' # ') tmp++;
if (tmp==1) ans++;
}
cout<<ans<< ' \12 ';
}
return 0;
}