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
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int n; scanf("%d",&n); while(n--) { int a,b,i,j,sum=0; char c[101][101]; memset(c,0,sizeof(c)); scanf("%d%d%*c",&a,&b); for(i=1; i<=a; i++) { for(j=1; j<=b; j++) { scanf("%c",&c[i][j]); if(i==1&&c[i][j]=='#')sum++; if(i==a&&c[i][j]=='#')sum++; if(j==1&&c[i][j]=='#')sum++; if(j==b&&c[i][j]=='#')sum++; } scanf("%*c"); } for(i=1; i<=a; i++) for(j=1; j<=b; j++) { int k=0; if(c[i][j]=='.') { if(c[i+1][j]=='#')k++; if(c[i-1][j]=='#')k++; if(c[i][j-1]=='#')k++; if(c[i][j+1]=='#')k++; if(k==1)sum++; } } printf("%d\n",sum); } return 0; }